This book is to collect code snippets I find useful, and don't want to let them be lost forever.
This section contains command snippets for Linux. Bash scripts, or simple commands that I needed once and had to google for it.
This is how you create a dummy file (without any real content). Great to test uploads, or anything that requires certain sized files, but you just don't have them ready.
dd if=/dev/zero of=test.bin bs=10000000 count=1
if defines the file you read in content from, of is the output file. bs is the size of the file (amount of data read in) that will be created. count defines how many blocks you want to copy, in this case 1 is fine.
While working with killes on an occasion in Germany he needed the functionality to get all the given functions from a file, as if grepping complete functions, from the start till the closing }. He sent it to me, so I can save it for the lucky future, unserialized it for you to be able to read. It starts at the commend block above the code, and saves it until the closing bracket, and prints it.
It assumes that you have no leading space before the closing bracket, nor the function declaration, and also note that it matches theme_* functions.
BEGIN {
p=0;
}
{
if ($0 == "/**") { # start copying
p = 1; # copy flag 1
o = ""; # initial content
pp = 0; # encounter flag 0
}
if (p == 1) { # we are copying
o = o""$0"\n"; # append line to content
if ($0 ~ "^function theme_") {
pp = 1; # encounter flag 1
}
}
if ($0 ~ "^}") { #finish copying
p = 0; # copy flag 0
if (pp == 1) { # if we are at the end AND we encountered the function
print o; # print the block
o="";
}
}
}
END {}