Saturday, March 12, 2011

emacs un-declaring/removing function or variable

Every time I forget this and look it on the reference I can never find again, or takes me so damn long.

How to unbound/undeclare/remove/unset a function:
(fmakunbound symbol)
Where symbol is a function name.

There's also a version for unsetting variables:
(makunbound symbol)
Where symbol is obviously a variable.

Friday, March 11, 2011

Earthquake

Damn, there just was a huge earthquake.
My bookshelf would have fell down if I hadn't held it. I live in the 8th floor, and I really thought this building was going down!
Good thing it didn't><.
My microwave and lots of stuffs fell to the floor though, and some electronic devices lost their power cable... Besides my computer desk looks like crap.
But still, as long as I have a change to get a cute Japanese lady, I'm all for it!!

Tuesday, March 8, 2011

auto-window opener (download helper for free users in download sites)

Being totally sick of my thesis and my slides for the presentation I gotta do tomorrow, I wrote some greasemonkey scripts to help me automate as much as possible (and remove those annoying Ads...) downloading as a free user.
I wrote three scripts; for filefactory.com, filesonic.com, and for uploaded.to.
You can see them in here.

The thing is, you'd still have to click on the links after a period of time (the download site usually prevents you to download files continually without waiting, just to annoy you).
So I also made a little page that does that for me, and added the ability to read links in html source code, so you can just a page with lots of hotfile.com's links, and copy them right away.
I put it in my webiste.

Ah, I'm so sick of college.

I love awk, grep, and sort

Not to say the obvious (which is I like linux a lot!), awk really comes handy so often...
I have some files of my research (I'm a senior at college), which have like 9 columns of rather big numbers, representing some benchmark results.

Having to put them in an openoffice spreadsheet after sorting them, my friends grep, awk , and sort really helped me out:

blosum 0.824/0.735 0.894/0.432 0.694/0.349 0.728/0.364 0.832/0.595 0.817/0.610 0.794/0.495
gonnet 0.865/0.781 0.934/0.596 0.756/0.447 0.822/0.543 0.876/0.661 0.864/0.692 0.851/0.606
pam 0.764/0.639 0.851/0.321 0.582/0.175 0.672/0.161 0.666/0.388 0.746/0.485 0.707/0.337
jtt_aa_codon 0.840/0.747 0.927/0.562 0.769/0.494 0.798/0.439 0.809/0.555 0.842/0.653 0.829/0.559

I have a file with data like this (a lot more though...), and I want to sort those three fields by the 7th column's left value, and also separate the values divided by "/" and obviously print the first field...

$grep -E "pam|blosum|gonnet" whole_hyou.txt |awk '{print $1, $7}'|awk '{split($2, second, "/"); print $1, second[1], second[2]}'|sort -k 2 -r

gonnet 0.864 0.692
blosum 0.817 0.610
pam 0.746 0.485

Ah, and then I just select and press the mid button in openoffice, click on "space" as a separator, and I get right done what I wanted to do in almost no time...
I've seen my friends trying to do the same thing in windows...
I would kill myself/or die of boring if I had to waste my time like that!

Wednesday, March 2, 2011

php doing multiple commands without hanging

For some reason, running multiple commands (for programs that take long) while redirecting one of their outputs to a file, in the background, hanged my browser in php. My command was something like this:

command.sh somefile.txt &> output.txt && some_other_command.sh somefile2.txt &
And my php code looked like this:
exec($command); //$command being the above string in single quotes


If run in the shell (command line) though, it works without any problem, correctly being run in the background.

I have no idea what the reasons are, but there are three points that you have to be careful with when running multiple commands like this:

  1. The exec() function. Even after correcting the code (no. 2 and 3), it would still hang when using it.
    The solution is to use popen()/pclose(), and fread().
    E.g. instead of:
    exec($command)
    do something like:
    $handle = popen($command, "r");
    fread($handle, 4);
    pclose($handle);

  2. The "&&" string. The program correctly returned status 0 (you can check that with "echo $?" in your shell). But this makes it hang too.
    The solution is to use ";" instead.
  3. The output redirection... have no idea why.
    The solution is to use the "tee" command to output to a file better.
So, the above code corrected would look like this:

command.sh somefile.txt |tee output.txt ; some_other_command.sh somefile2.txt &

And the php code would look something like:
$command = 'command.sh somefile.txt |tee output.txt ; some_other_command.sh somefile2.txt &'
$handle = popen($command, "r");
fread($handle, 4);
pclose($handle);


Although running the command in a sub-shell environment makes it easier to read (and maybe necessary).
I mean, instead of running it like:
command.sh somefile.txt |tee output.txt ; some_other_command.sh somefile2.txt &
You run it like:
(command.sh somefile.txt |tee output.txt ; some_other_command.sh somefile2.txt) &
So you can clearly see what the expression is like, and that it will be run as a background process.




My real command, included sending an e-mail, whose contents were also made with php.
Just in case anyone is interested...
$command = "(nohub nice -n 15 command.sh somefile.txt |tee output_log.txt ; mail -a $mail_header -s $mail_subject $mail_address <<EOF
$mail_contents
EOF

) &";
$handle = popen($command, "r");
fread($handle, 4);
pclose($handle);


Remember to use double quotation ("") in strings where you want php variables replaced ('$stuff' will return just the string '$stuff', while "$stuff" will return the actual contents of that string). It makes the code easier to read.
The beauty of this, is that sends you an e-mail after the program is done! And, as running in the background, it allows the user to just close the browser window without interrupting the program.

ももいろクローバー

ももいろクローバー(Momoiro clover)
They are the new idol group in Japan. Man they are cute!
I didn't like AKB48, and these girls are cute and very funny (they appeared in a comedy TV show and were funny as hell).

Some of their music vids:





automatic log out

I was answering a form for a bit over one hour, and when I finally finished and pressed the submit button, I got a made-by-php-like page saying I was logged out because of no activity for too long...
All that text...
gone.

I can't believe such damn pages still exist!! I was so gonna kick my computer!
The page was in a site that my company (the one I'm gonna work for from next month) is running, and was about what kind of job I wanted to do! So as you can guess I had to write lots and lots about my experience and stuffs...
I had to write it all over, and was terribly sleepy.
Damn those stupidly made pages, at least put a javascript timer telling you when you are going to be automatically logged out, or let me copy what I wrote by letting my go back the previous page!!