Archive

Archive for the ‘hacking’ Category

Script-Fu Template For Batch Processing In GIMP

January 31, 2009 edwinhere 4 comments

Time and again, I’ve wanted to do a set of operations on a large set of images. I knew that Script-Fu in GIMP could do the job, but I could never find a boiler plate code to act on all files in a directory.

This is a little something I wrote to reduce the number of colors and remove the alpha channel of a large number of PNG files in a directory:

(define (smallify dir)
  (let*
    ((files-list (car (cdr (file-glob dir 0))))
     (do-one (lambda (f) (let*
                           ((i (gimp-file-load RUN-NONINTERACTIVE f f))
                            (d (gimp-image-flatten (car i))))
                           (begin
                             (gimp-posterize (car d) 5)
                             (file-png-save2 RUN-NONINTERACTIVE (car i) (car d)
                              f f 0 9 0 0 0 0 0 0 0)
                             #t)))))
    (map do-one files-list)))

Here is the generic template that can be used for batch processing a lot of images in one directory:

(define (do-many dir)
  (let*
    ((files-list (car (cdr (file-glob dir 0))))
     (do-one (lambda (f) (your-code-goes-here))))
    (map do-one files-list)))

In order to use the above template, first replace (your-code-goes-here) with the s-expression you need to change the images. (Hint: Use Filters > Script-Fu > Console > Browse… to see the documentation). While doing so keep in mind that f will contain the full path to each file in your directory; you can use f to do what you wish that file.

Then in Script-Fu console, paste the resulting code in the text field there and press enter. This will define the do-many function. Then you can call it like this:

(do-many "/home/edwin/alotafimages/*.png")

And your s-expressions will act on all PNG files in that directory.

Categories: IT, computers & foss, hacking

Blast This

October 17, 2008 edwinhere 1 comment

Heard this in a podcast.

BLAST this sequence: atgttcc tgtccttccc caccaccaag acctacttcc cgcacttcga cctgagccac ggctctgccc aggttaaggg ccacggcaag aaggtggccg acgcgctgac caacgccgtg gcgcacgtgg acgacatgcc caacgcgctg tccgccctga gcgacctgca cgcgcacaag cttcgggtgg acccggtcaa cttcaagctc ctaa

Instructions: Copy and Paste the DNA sequence into the query window, and hit the blast button. Try again selecting the non-human, non-mouse database from the drop down menu. What organism is the exact same gene found in? WTF?

I am getting that house mosquitoes and us share this same gene. We use it to make haemoglobin but mosquitoes use it for tissue control, whatever that means. May be they do an alternative splicing to make a different protein?

Nature has excellent code reuse. Better than most Microsoft, Adobe programmers. LOL!

Categories: hacking, science

Magic Squares as Vectors to a field of Reals

August 16, 2007 edwinhere Leave a comment

Pattern 1: Multiplication of a scalar into the quantity and the result is of the same type as the original quantity.

displaystyle{ M = left(begin{array}{cccc} 16 & 3 & 2 & 13\ 5 & 10 & 11 & 8\ 9 & 6 & 7 & 12\ 4 & 15 & 14 & 1 end{array}right)} 

is a magic square.

displaystyle{ 3 M = left(begin{array}{cccc} 48 & 9 & 6 & 39\ 15 & 30 & 33 & 24\ 27 & 18 & 21 & 36\ 12 & 45 & 42 & 3 end{array}right)}  

is also a magic square.Pattern 2: Add 2 of the quantity and the result is of the same type as the original quantities.

displaystyle{ left(begin{array}{cccc} 16 & 3 & 2 & 13\ 5 & 10 & 11 & 8\ 9 & 6 & 7 & 12\ 4 & 15 & 14 & 1 end{array}right) + left(begin{array}{cccc} 20 & 16 & 6 & 7\ 2 & 11 & 13 & 23\ 19 & 21 & 4 & 5\ 8 & 1 & 26 & 14 end{array}right) = left(begin{array}{cccc} 36 & 19 & 8 & 20\ 7 & 21 & 24 & 31\ 28 & 27 & 11 & 17\ 12 & 16 & 40 & 15 end{array}right)}  

In the above statement, the sum is also a magic square.Any quantities that obey Pattern one and 2 are vectors, and hence unit vectors can be defined. The norm a.k.a the magnitude can be defined as the constant sum of magic square.

displaystyle{ hat{a} = left(begin{array}{cccc} 1 & 0 & 0 & 0\ 0 & 0 & 0 & 1\ 0 & 1 & 0 & 0\ 0 & 0 & 1 & 0 end{array}right)  hat{b} = left(begin{array}{cccc} 0 & 1 & 0 & 0\ 0 & 0 & 0 & 1\ 0 & 0 & 1 & 0\ 1 & 0 & 0 & 0 end{array}right)  hat{c} = left(begin{array}{cccc} 0 & 1 & 0 & 0\ 0 & 0 & 1 & 0\ 1 & 0 & 0 & 0\ 0 & 0 & 0 & 1 end{array}right)  hat{d} = left(begin{array}{cccc} 0 & 0 & 0 & 1\ 0 & 1 & 0 & 0\ 1 & 0 & 0 & 0\ 0 & 0 & 1 & 0 end{array}right) } 

 

displaystyle{ hat{e} = left(begin{array}{cccc} 0 & 0 & 0 & 1\ 1 & 0 & 0 & 0\ 0 & 0 & 1 & 0\ 0 & 1 & 0 & 0 end{array}right)  hat{f} = left(begin{array}{cccc} 0 & 0 & 1 & 0\ 0 & 1 & 0 & 0\ 0 & 0 & 0 & 1\ 1 & 0 & 0 & 0 end{array}right)  hat{g} = left(begin{array}{cccc} 1 & 0 & 0 & 0\ 0 & 0 & 0 & 1\ 0 & 1 & 0 & 0\ 0 & 0 & 1 & 0 end{array}right)  hat{h} = left(begin{array}{cccc} 1 & 0 & 0 & 0\ 0 & 0 & 0 & 1\ 0 & 1 & 0 & 0\ 0 & 0 & 1 & 0 end{array}right) }  

Since there are seven unit vectors we are dealing with a 7th dimensional space.

displaystyle{ 6 hat{a} + 2 hat{b} + hat{c} + 8 hat{d} + 5 hat{e} + 2 hat{f} + 10 hat{g} = left(begin{array}{cccc} 16 & 3 & 2 & 13\ 5 & 10 & 11 & 8\ 9 & 6 & 7 & 12\ 4 & 15 & 14 & 1 end{array}right) } 

Categories: hacking, philosophy

Testing MathML

August 16, 2007 edwinhere 1 comment

$displaystyle{ lim_{xtoinfty} f(x) = k choose r + frac ab sum_{n=1}^infty a_n + left{ frac{1}{13} sum_{n=1}^infty b_n right} }$

Hmm.. looks like it works! But I had to sacrifice the cool look for blockquotes.

Categories: hacking

Added LaTex support

August 3, 2007 edwinhere 1 comment

I had always wanted to type equations in this blog. Now this site allows me to do just that. Most probably I am going to modify the greasemonkey script to use the that is installed in this PC instead of querying mimtex.cgi URL that the script relies on. But that is going to be hard because it is hard to use greasemonkey to use local executables. Moreover I will need to upload the equations to Picasa Web.OK here is my first equation:

Categories: hacking

I have a Mac

June 16, 2007 edwinhere Leave a comment

I should have made this post a long time ago but I guess all godless and girly things made it late. It is a Macbook Pro 15″.

Categories: hacking, my life

Kevin Mitnick Resurrected

April 3, 2006 edwinhere Leave a comment

I learned VNC Server DLL Injection today. It is a technique used by hackers to gain access to the dektop of an OS. I gained access to my friend’s Windows desktop in the next room from Linux PC.

It was possible because of the Microsoft LSASS MSO4-011 Overflow in his PC. This stack overflow enabled us to write arbitary executable code into the memory. Hackers usually use this overflow to spawn a shell. ( see figure on the above )

But yesterday I read about a new technique that let hackers to upload a Win32 DLL. And guess what, I uploaded an entire VNC Server to my friends PC. I can see & interact with his screen and I got a shell! TADA! (see figure above).

Categories: hacking, my life

In other news…

August 27, 2005 edwinhere Leave a comment

Viju Jacob George tried to do a prank on me, but it backfired! He sent me a URL which looked like a psychology test. The test asked you to input the names of the girls you had a crush on. Some how I guessed that this was a prank. So I entered some vulgar comments about him in those text fields and to my own astonishment everything got mailed to his e-mail address! Later I met Viju…he tells me he will get his revenge some day (oops! thats scary…).

I think Barnabas rectified the problem with the peer evaluation system. They are filtering non-alpha-numeric characters from the password field. But they are not filtering the username field still now….this could pose a problem. But I dont have time to think about all that right now. Exams will start on Sep 5th. Lets play Kevin Mitnick later when I get some time.

Categories: friends, hacking

Kevin Mitnick in the making…

August 26, 2005 edwinhere 1 comment

I must be happiest person on this planet today. I hacked into the Peer Evaluation System at school using a simple SQL Injection technique. I demonstrated it to my subject leader Dr. Yin Choon Meng by logging in to his account. I did a Username: yincm and Password: ‘ OR ‘x’='x
Now that means the password condition will always be true and that means I can log in into anyone’s account.

The bad side of the story was that Mr. Barnabas Woon (SQL Teacher) was also present at the demonstration and he did’nt like it. Only later did Justin (senior buddy) tell me that Peer Evaluation System was designed by Barnabas and his students. No wonder he is angry with me.

Barnabas reminds me of Prof. Snape in Harry Potter….!

I think they will rectify it soon before it is too late.

Categories: hacking, my life