129 karma · joined Oct 26, 2014 (12y ago) · 132 submissions
1.
4 points · by 101914 · 9y ago · discuss
comment 11y ago · link · parent
Go to conqueringthecommandline.com/book
Save the page source
Insert the filename into the script below
Alternatively, omit filename and pipe the source of the page to the script
Works with BSD sed as well as GNU sed; first lesson: portability
a=$(printf '\004')
sed 's/s3_url/'"$a"'&/' \
|tr '\004' '\012' \
|exec sed '
s/\\u0026/\&/g;
s/.*s3_url.:.//g;
s/\".*//g;
/https:.*Amz/!d;
' filename
I do not recommend this "book". Look at the hoops they make readers jump through. Try grymoire.com; much better and no Javascript requiredcomment 11y ago · link · parent
Alas, the interviewer asked no technical, interesting questions. There is a portable assembly language called MINIMAL that is used in spitbol. This could be a topic for an entire story itself.
comment 11y ago · link · parent
My recollection is this was published on the author's site years before being added to the "handbook" on the FreeBSD website. I could be wrong. Perhaps check archive.org.
comment 11y ago · link · parent
He's wrong of course about being the only user.
I love this software, along with k/q. I admire the work Mr. Shields has put into this project. I especially like the use of musl and provision of static binaries.
I do not use Perl, Java, Python, Javascript, Go, Rust, Closure, etc., etc. Whatever the majority of people are recommending, that is generally not what I use. It just does not appeal to me.
I guess I am stubborn and stupid: I like assembly languages, SPITBOL, k/q, and stuff written by djb. Keep it terse. Ignore the critics.
Yet this is now on the front page of HN. Maybe because it is the weekend? I really doubt that the software I like with ever become popular. But who knows? Maybe 10 years from now I will look at this post and marvel at how things turned out.
There is no "structured programming" with spitbol. No curly braces. Gotos get the job done. Personally, I do not mind gotos. It feels closer to the reality of how a computer operates.
Would be nice if spitbol was ported to BSD in additon to Linux and OSX. As with k/q I settle for Linux emulation under BSD.
comment 11y ago · link · parent
"Shell languages are defined by their terseness."
It is common to see people put a layer of verbosity on top of the Bourne shell (or system(3)) to make "a new shell".
It is also very common to see people put a layer of abstraction on top of a large, verbose scripting language and claim the result to be a new, "terse" language (with all the power of the shell).
But what I like about the Bourne shell is that it is built from only C. And it does not add too much verbosity. It is, as you say, defined by its terseness.
There is also terseness in the roff-like typesetting languages, assembly languages, FORTH, k/q, etc.
Compared to k/q, sh is verbose.
For me, verbosity means loss of power and loss of time.
I am glad there are terse languages.
They may never again be popular but I think they will always exist.
"The worst parts of the shell are the flow control structures..."
For some reason I dislike if/then/else. Instead I make heavy use return values, ||, test(1) and case/esac.
I always wished Bourne's shell (cf. Joy's C shell) made use of more C operators. There's a file called arith_lex.l in the Almquist sh source but these operators are not used in the sh language.
I would switch to the Plan 9 shell but Bourne sh remains more useful due to its ubiquity.
comment 11y ago · link · parent
"Q: Why did you choose Assembly?
A: It is easy, simple, and the language of real programmers."
Will he still believe this when he's older?
I hope so. Because it is the truth.
comment 11y ago · link · parent
# requirements:
# sh, sed (BSD ok), tr, openssl, ftp or some other httpclient
curl=ftp
file=${2-1.mp4} # default outfile
# itag #s are on the wikipedia page for youtube
case $# in
[12])
{
sed 's/http:/https:/' \
|while read a;
do
b=${a#*://};
c=${b%%/*};
{
printf "%b" "GET /${a#https://*/} HTTP/1.0\r\n";
printf "Host: $c\r\n";
printf "User-Agent: OK, Google.\r\n";
printf "Connection: close\r\n\r\n";
} \
|openssl s_client -ign_eof -connect $c:443 -verify 9
done \
|sed '
s,http,\
&,g;
' \
|sed '
/%3A%2F/!d;
/videoplayback/!d;
s,%3D,=,g;
s,%3A,:,g;
s,%2F,/,g;
s,%3F,?,g;
s/^M//g;
' \
|sed -e '
s/&itag=5//;t1
s/&itag=1[78]//;t1
s/&itag=22//;t1
s/&itag=3[4-8]//;t1
s/&itag=4[3-6]//;t1
s/&itag=1[346][0-9]//;t1
' -e :1 \
|sed '
s,%26,\
,g;
s,&,\
,g;
' \
|sed 's/%25/%/g' \
|tr '\012' '&' \
|sed 's/&$//';
echo
} \
|sed '
s,%3D,=,g;
s,%3A,:,g;
s,%2F,/,g;
s,%3F,?,g;
s/^M//g;
' \
|sed '
s/&https/\
\
https/g;' \
|sed 's/\\u0026.*//' \
|sed '/itag='"${1-.}"'/!d;'|{
read a;
exec $curl -4o $file $a;}
;;
*)
exec echo \
"usage: $0 itagno [outfile]
outfile: $file"
esaccomment 11y ago · link · parent
a=$(printf '\xb%-47.s' \
|nc -uw1 ntp.metas.ch 123 \
|exec xxd -s40 -l4 -p)
b=$(printf %d\\n 0x"$a")
c=$((b-2208988800))
date -r$c
There is a way to do the xxd step using original netcat.
Included with nc was a short program called nc-data.
It converts from btoa and atob for shoveling data to nc.Slower than xxd but still useful. It also shows octal, decimal and byte number.
Another exercise might be a one-liner for the TAICLOCK protocol: http://cr.yp.to/proto/taiclock.txt (Alternative to SNTP with smaller packets and support for leap seconds.)
comment 11y ago · link · parent
1. Get the video id. Retrieve HTML containing youtube /watch?v= urls or other urls that contain the video id. Extract the urls from the HTML or other markup garbage.
2. Retrieve the video. Feed the /watch?v= url to a script that does some "find and replace" on the absurdly long googlevideo urls. Below I have given an example of such a script. Complaints welcome. It takes a /watch?v= url on stdin and retrieves the video in the format specified on the command line.
3. Play the video. ffmpeg libraries, mplayer, etc.
Whatever it is Flash does in the process of watching youtube videos (I am quite sure it is not step 3), I do not need it.
Thus even if by not using Flash or a complex "modern" web browser to watch youtube videos somehow were to reduce my exposure to vulnerabilities that routinely occur in such software, I would not care. Because the reason I do not use Flash is.... because I do not need it.
# proof of concept: video retrieval
# requirements:
# sh, sed, tr, openssl, ftp
# Adobe Flash not required
# HTML5 not required
# Python not required
# Awk not required
# web browser not required
curl=ftp
file=1.mp4 # default outfile
url=www.youtube.com # example
# itag #s are on the wikipedia page for youtube
f061(){
sed '
s,%3D,=,g;
s,%3A,:,g;
s,%2F,/,g;
s,%3F,?,g;
s/
//g;
'
} f060(){
sed -e '
s/&itag=5//;t1
s/&itag=1[78]//;t1
s/&itag=22//;t1
s/&itag=3[4-8]//;t1
s/&itag=4[3-6]//;t1
s/&itag=1[346][0-9]//;t1
' -e :1
}
f062(){
sed '
s,http,\
&,g'
}
f063(){
sed '
/%3A%2F/!d;
/videoplayback/!d'
}
f064(){
sed '
s,%26,\
,g;
s,&,\
,g;
'
}
f065(){
sed 's/&https/\
\
https/g;'
}
f066(){
sed 's/\\u0026.*//'
}
f067(){
sed '/itag='"${1-.}"'/!d;'
}
f068(){
sed 's/%25/%/g'
}
f069(){
tr '\012' '&'
}
f070(){
sed 's/&$//'; echo
}
f071(){
local a061 a062 a063;
while read a; do
case $a in
https://*)a061=${a#https://*/} ;;
http://*)a061=${a#http://*/} ;;
*)a061=${a#*/} ;;
esac;
a062=${a#*://};
a063=${a062%%/*};
printf "%b" "${1-GET} /${a061} HTTP/1.0\r\n"
printf "Host: ${a063}\r\n";
printf "User-Agent: GoogleAnalytics 1.5.1\r\n";
printf "Connection: Close\r\n";
printf "\r\n";
done;
}
f072(){
openssl s_client -ign_eof -connect $1:${2-443} -verify 9
}
case $# in
[12])
{
f071 \
|f072 $url \
|f062 \
|f063 \
|f061 \
|f060 \
|f064 \
|f068 \
|f069 \
|f070
} \
|f061 \
|f065 \
|f066 \
|f067 $1 \
|{
read a;
exec $curl -4o ${2-$file} $a ;
}
;;
*)
exec echo \
"usage: $0 itagno [outfile]
outfile: $file"
esaccomment 11y ago · link · parent
I have always thought about the idea of a shell that could return values from other registers.
I guess there are reasons this would be a stupid experiment. Or maybe I am the only one could see the utility of it.
Did anyone see Bourne's keynote at BSDCan about how sh was developed? I only looked at the slides.
Meanwhile I use a debgger for asm programs called ald to trace register values. I found a nasty bug in this program but I am not aware of any similar debuggers aimed at asm (cf. C).
comment 11y ago · link · parent
Opinion: Personally, because I strive to learn more than to be "productive", I prefer languages that force the author to write her own libraries. As I see it, the alternative is languages that discourage this, effectively coercing the author to use other people's libraries, the quality over which she has no control.
Opinion: For me, the bad part is that there are so many poorly thought out C functions in the wild (even including the "standard" ones); the good part is that the C language encourages authors to write their own libraries.
Given the choice, I still prefer assembly to C. I guess this is because I prefer to write small programs; perhaps I am not smart enough to write large ones.