| Author |
Message |
technosaurus

Joined: 18 May 2008 Posts: 3843
|
Posted: Thu 13 Dec 2012, 19:58 Post subject:
learning by viewing contest Subject description: the prize is pride |
|
Submit your enlightening code here for others to figure out and learn. The first one to get it right, gets added to this score card.
Point count:
| Code: | | nc -ll -p 80 -e sh -c 'while read L;do set $L;case "$1" in [Gg][Ee][Tt])F=${2##*/};cat ${F%%\?*};break;;esac;done' | MinHundHettePerro 1 (bash/shell)
Current open contests:
javascript:
| Code: | | function F(x){var t=XMLHttpRequest();try{t.open("HEAD",x,false);t.send();return t.status!=404}catch(n){return false}} |
C:
| Code: | | #define F(i,a) ({ int j=0;while(a[j] != NULL){a[j]=a[j+i];j++;}}) |
_________________ Puppy Web Desktop Now with pet packages - Pet Packaging 100 & 101
Last edited by technosaurus on Fri 14 Dec 2012, 10:12; edited 2 times in total
|
|
Back to top
|
|
 |
MinHundHettePerro

Joined: 05 Feb 2009 Posts: 831 Location: SE
|
Posted: Thu 13 Dec 2012, 20:32 Post subject:
|
|
Right, ...
Listen on your computer's port 80 if someone is trying to connect, if there's someone actually trying that, check if any line in the header begins with (any combination of capitals and small letters) "get", if so, set variable "F" to whatever follows the last "/" following the initial "get _blank_", then print whatever precedes the first (remaining) "?" - otherwise continue ...
Yes, the parts to be read - and output - are probably part of the http-protocol , which I don't know in _any_ detail at all
Or, whatever ... / MHHP
_________________ Celeron 2.8 GHz, 1 GiB RAM, i82845 graphics, many partitions, Pupmode 12 (13)
Mostly running Slacko & 214X
Nämen, vaf.... ln -s /dev/null MHHP
|
|
Back to top
|
|
 |
technosaurus

Joined: 18 May 2008 Posts: 3843
|
Posted: Fri 14 Dec 2012, 00:23 Post subject:
|
|
| MinHundHettePerro wrote: | | then print whatever precedes the first (remaining) "?" | close enough, it uploads the file from the directory where it is run ... basically it is a file server designed to ignore directory structure (for mirroring several javascript CDNs like ajax.googleapis.com, cdnjs.cloudflare.com,ajax.aspnetcdn.com,... without having to have duplicate files for each different directory structure)
Here is a fuller implementation that assumes your mirrored sites are set up in /etc/hosts
| Code: | #!/bin/sh
nc -ll -p 80 -e sh -c '
while read A B DUMMY
do
case "$A" in
[Gg][Ee][Tt])
FULL=$B
F=${FULL##*/}
F=${F%%\?*}
[ -f "$F" ] && cat "$F" && break
;;
[Hh][Oo][Ss][Tt]*)
[ -f "$F" ] && break
HOST=${B:0:$((${#B}-1))}
sed -i "s/hosts:\t\tfiles /hosts:\t\t/g" /etc/nsswitch.conf
wget -t 0 -q --no-dns-cache $HOST$FULL
sed -i "s/hosts:\t\t/hosts:\t\tfiles /g" /etc/nsswitch.conf
cat "$F"
break
;;
esac
done
' |
here is an example of the hosts file
| Code: | 127.0.0.1 localhost puppypcXXXXX
127.0.0.1 ajax.googleapis.com
0.0.0.0 pagead2.googlesyndication.com |
the 127.0.0.1 sites use your local mirror instead (no more waiting for ajax.googleapis.com)
the 0.0.0.0 sites get completely ignored (ad removal etc...)
_________________ Puppy Web Desktop Now with pet packages - Pet Packaging 100 & 101
|
|
Back to top
|
|
 |
technosaurus

Joined: 18 May 2008 Posts: 3843
|
Posted: Fri 14 Dec 2012, 01:20 Post subject:
|
|
here is a simple, but useful javascript function:
| Code: | | function F(x){var t=XMLHttpRequest();try{t.open("HEAD",x,false);t.send();return t.status!=404}catch(n){return false}} |
obfuscated for your education
_________________ Puppy Web Desktop Now with pet packages - Pet Packaging 100 & 101
|
|
Back to top
|
|
 |
MinHundHettePerro

Joined: 05 Feb 2009 Posts: 831 Location: SE
|
Posted: Fri 14 Dec 2012, 17:33 Post subject:
Re: learning by viewing contest Subject description: the prize is pride |
|
| technosaurus wrote: |
Current open contests:
C:
| Code: | | #define F(i,a) ({ int j=0;while(a[j] != NULL){a[j]=a[j+i];j++;}}) |
|
Yes, right ... don't know C either but, since I enjoy deciphering code I don't know, I'll wager a stab at it | Code: | #!/bin/sh
# C: #define F(i,a) ({ int j=0;while(a[j] != NULL){a[j]=a[j+i];j++;}})
# C Code snippet above could probably be used for many things but I'll try a dd analogy for reading and "streaming" a file by a set chunk-size ...
# par example:
i="a number"
a="a file to transfer"
F() { dd if="$a" bs="$i"}
# the indexing variable j would correspond to the "count"-parameter for dd as of above but, the need to index (and up the index by one until there are no more chunks) would be unnecessesary using dd with an input file of finite length.
|
Cheers / MHHP
_________________ Celeron 2.8 GHz, 1 GiB RAM, i82845 graphics, many partitions, Pupmode 12 (13)
Mostly running Slacko & 214X
Nämen, vaf.... ln -s /dev/null MHHP
|
|
Back to top
|
|
 |
technosaurus

Joined: 18 May 2008 Posts: 3843
|
Posted: Fri 14 Dec 2012, 18:54 Post subject:
|
|
That one is intentionally misleading, inefficient code that I actually used before I understood how c strings relate to pointers... Hint: s+=n would be functionally equivalent.
_________________ Puppy Web Desktop Now with pet packages - Pet Packaging 100 & 101
|
|
Back to top
|
|
 |
SFR

Joined: 26 Oct 2011 Posts: 569
|
Posted: Fri 14 Dec 2012, 21:06 Post subject:
Re: learning by viewing contest Subject description: the prize is pride |
|
| technosaurus wrote: | C:
| Code: | | #define F(i,a) ({ int j=0;while(a[j] != NULL){a[j]=a[j+i];j++;}}) |
|
I still haven't started to learn C, but I can not see any other application of that:
Does this code shifts all elements of 'a' array 'i' position(s) to the left?
Greetings!
_________________ [O]bdurate [R]ules [D]estroy [E]nthusiastic [R]ebels => [C]reative [H]umans [A]lways [O]pen [S]ource
Omnia mea mecum porto.
|
|
Back to top
|
|
 |
technosaurus

Joined: 18 May 2008 Posts: 3843
|
Posted: Sat 15 Dec 2012, 00:47 Post subject:
|
|
@SFR - congrats. Yes it is the equivalent of shift in bash.
_________________ Puppy Web Desktop Now with pet packages - Pet Packaging 100 & 101
|
|
Back to top
|
|
 |
technosaurus

Joined: 18 May 2008 Posts: 3843
|
Posted: Thu 20 Dec 2012, 17:17 Post subject:
|
|
here is another javascript
| Code: | function
q(){for(var a="?",c=arguments,b=c.length;(a+=c[--b])&&b;a+="&")
return a}
//which is the same as
function
q(){return"?"+[].splice.call(arguments,0).join("&")} |
_________________ Puppy Web Desktop Now with pet packages - Pet Packaging 100 & 101
|
|
Back to top
|
|
 |
|