Archiwum dla kategorii “Studia”

Oto jaka siła drzemie w Bash’u! Nie spodziewałem się tego. Skrypt wykorzystuje Netcat.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#!/bin/bash
 
function debug {
    local severity="$1"
    shift
    local message="$@"
 
    echo -n "`date -u`"    1>&2
    echo -ne '\t'        1>&2
    echo -n "$severity"    1>&2
    echo -ne '\t'        1>&2
    echo "$message"        1>&2
}
 
function fix_path {
    echo -n "$1" | head -n 1 | sed 's|^[/.-]*||' | sed 's|/\.*|/|g'
}
 
function serve_dir {
    local dir="`fix_path "$1"`"
    if [ "$dir" = "" ]; then
        dir="./"
    fi
    echo 'HTTP/1.1 200 OK'
    echo 'Content-type: text/html;charset=UTF-8'
    echo
    echo LISTING "$dir"
    echo '<br />'
    ls -p "$dir" | sed -e 's|^\(.*\)$|<a href="/'"$dir"'\1">\1</a><br />|'
}
 
function serve_file {
    echo 'HTTP/1.1 200 OK'
    echo 'Content-type: application/x-download-this'
    echo
    local file="`fix_path "$1"`"
    debug INFO serving file "$file"
    cat "$file"
}
 
function process {
    local url="`gawk '{print $2}' | head -n 1`"
    case "$url" in
        */)
            debug INFO Processing "$url" as dir
            serve_dir "$url"
            break
            ;;
        *)
            debug INFO Processing "$url" as file
            serve_file "$url"
            ;;
    esac
}
 
function serve {
    local port="$1"
    local sin="$2"
    local sout="$3"
 
    while debug INFO Running nc; do
 
        nc -l -p "$port" < "$sin" > "$sout" &
        pid="$!"
 
        debug INFO Server PID: "$pid"
 
        trap cleanup SIGINT
        head -n 1 "$sout" | process > "$sin"
        trap - SIGINT
 
        debug INFO Killing nc
 
        kill "$pid"
    done
 
    debug INFO Quiting server
}
 
function cleanup {
    debug INFO Caught signal, quitting...
    rm -Rf "$tmp_dir"
    exit
}
 
tmp_dir="`mktemp -d -t http_server.XXXXXXXXXX`"
sin="$tmp_dir"/in
sout="$tmp_dir"/out
pid=0
port="$1"
 
mkfifo "$sin"
mkfifo "$sout"
 
debug INFO Starting server on port "$port"
serve "$port" "$sin" "$sout"
cleanup

Comments Brak komentarzy »

Dziś kilka zadanek gdzie zobaczymy jak działa filtr uśredniający. Zrobimy także proste menu wyboru, a także zapis naszej animacji do pliku video.
Przeczytaj resztę wpisu »

Comments 1 komentarz »

Dziś pokażę jak w szybki sposób zakodować obraz. Zakodować czyli ukryć w nim jakaś tajną treść, którą będzie można odczytać tylko gdy będzie ktoś posiadał oryginalną matrycę w której ukryliśmy inny obraz. Jak to wygląda? Poniżej zakodowany obraz:

wynik kodowania

Jaką tajną wiadomość ukryłem w tym obrazie? Zaraz się przekonamy…
Przeczytaj resztę wpisu »

Comments 1 komentarz »

Efekt z C++, zadanko z programowania. Ramka powiększa się do zadanych wymiarów.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include <stdlib .h>
#include <stdio .h>
#include <iostream>
#define MAX 128
using namespace std;
 
int gotoxy(int x, int y)
{
	char essq[MAX]={0}; 
	sprintf(essq, "\033[%d;%df", y,x);
	printf("%s", essq);
	return 0;
}
 
void draw(int x1,int y1,int x2,int y2,char z) 
{
	int i;
	for (i=x1; i< =x2; i++) 
	{
		gotoxy(i,y1);
		cout<<z;
		gotoxy(i,y2);
		cout<<z;
	}
	for (i=y1+1; i<y2; i++)
	{
		gotoxy(x1,i);
		cout<<z;
		gotoxy(x2,i);
		cout<<z;
	}
}
 
void boom(int x1,int y1,int x2,int y2,char z) 
{
	int x,y,m=0,n=0;
 
	((x1+x2)%2) ? x=((x1+x2)/2)+1 : x=(x1+x2)/2 ;
	((y1+y2)%2) ? y=((y1+y2)/2)+1 : y=(y1+y2)/2 ;
 
	int i=x,j=y;
 
	do
	{
		system("clear");
		if(i<=x2)
		{
			m++;
			i++;
		}
		if(j<=y2)
		{
			n++;
			j++;
		}
		draw(x-m,y-n,x+m,y+n,z);
		getchar();		
	}while((i<=x2) || (j<=y2));
}
 
int main() 
{
	int x1=10, x2=40, y1=10,y2=40;
	char z='o';
	boom(x1,y1,x2,y2,z);
	cout<<endl;
 
}

Comments Brak komentarzy »

(c) 2007 by Michał Terbert