Code Dose

Here we discuss new language features and tools.
A new function everyday to try out and talk about.

Annoying your friend with Shell (not sea shell)

Trick

I was playing around with my friends a little and came up with this super annoying prank. It is potentially hazardous to leave your machine unlocked in a public place, if you find that your friend has violated this condition, its time to play a small prank on him/her.

What we will try to do is kill his/her terminal as soon as it is opened. Trust me this can be super frustrating for the victim.

Simply open ~/.bashrc (if it is not there then make one) and paste the following lines of code in it

a=`ps -eaf | grep terminal | cut -f 3 -d ” ” | head -n 1`
kill $a

Tada !! you are done. Next time when your friend tries to open his/her terminal, well they cannot it will just shut down 🙂

Explaination

The script is very simple and deserves only a single line of explanation. Find the process named terminal, get its pid and then kill it. The reason why I do a head -n 1 is because ps will output 2 processes containing the keyword terminal. One of them will belong to grep (The second one). So we chose the first one.

Oh Lord make it stop

If you have fallen a victim to this prank, switch to tty1 (try pressing crtl+alt+f1), login, open the ~/.bashrc file and just delete the 2 lines mentioned above. Be sure to logout.

This did not work

Your victim is smarter than you. His default shell is not bash or his gtk window is not named terminal. Figure it out yourself.

I feel more adventurous 

Every recipe can be spiced up. Try the one below

a=`ps -eaf | grep terminal | cut -f 3 -d ” ” | head -n 1`
echo “I will not work today. I am going to sleep !!”
# If you are not sure if beep is installed on your friends machine, leave the next line out
beep -f 800 -l 500
sleep 2
kill $a

Have fun, you can maybe check the man page of those commands and see if there are other more innovative ways of playing with the script.

A prank is only fun as long as you don’t cross the line 🙂

 

 

Funny effect using jQuery.

I was just playing around with jQuery and accidental created this really funny effect. Keeping this post short as I have to get back to work I will post the code here –

<html>
<head>
<script type=”text/javascript” src=”jquery-1.7.js”></script>
<script type=”text/javascript”>
// we will add our javascript code here
$(document).ready(function (){
$(“#mylink”).toggle(function (){
$(“#mydiv”).hide(‘slow’);
}, function() {
$(“#mydiv”).show(‘slow’);
});
});
</script>
</head>
<body>
<a href=”#” id=”mylink”>My link</a>
<div id=”mydiv” align=”center”>This is my div.</div>
</body>
</html>

The code functioned the way it without adding align=”center” in the div tag. However when I added that it gave me a smooth sliding effect 😛

Sadly I do not have a video upgrade, so I cannot post my video here 😦 I urge my readers to copy paste the code and try it out, it should be fun.

 

Hello World

The first post that WordPress automatically creates when a new blog is created is titled ‘Hello World’. However its in English and not everyone understands it. So I have tried to paraphrase it in some other more human friendly languages.

echo “Hello World”

printf(“Hello world\n”);

cout<<“Hello World”);

<p>Hello World</p>

print “Hello World”

window.document.write(“Hello World”);

alert(“Hello World”);

System.out.println(“Hello World”);

writeln(“Hello World”);

write(1,”Hello World”,11);

Put_Line(“Hello World”);

.model tiny
.code
org 0x100h
hello_world proc
mov ah,09h
lea dx,dis
int 21h
hello_world  endp
dis db ‘Hello World$’
end

0000400 ed31 8949 5ed1 8948 48e2 e483 50f0 4954
0000410 c0c7 0500 0040 c748 10c1 4005 4800 c7c7
0000420 04e4 0040 c7e8 ffff f4ff 9090 8348 08ec
0000430 8b48 6105 2004 4800 c085 0274 d0ff 8348
0000440 08c4 90c3 9090 9090 9090 9090 9090 9090
0000450 4855 e589 4853 ec83 8008 783d 2004 0000
0000460 4b75 e8bb 6006 4800 058b 0472 0020 8148
0000470 e0eb 6006 4800 fbc1 4803 eb83 4801 d839
0000480 2473 0f66 441f 0000 8348 01c0 8948 4d05
0000490 2004 ff00 c514 06e0 0060 8b48 3f05 2004
00004a0 4800 d839 e272 05c6 042b 0020 4801 c483
00004b0 5b08 c35d 6666 2e66 1f0f 0084 0000 0000
00004c0 8348 283d 2002 0000 4855 e589 1274 00b8
00004d0 0000 4800 c085 0874 bf5d 06f0 0060 e0ff
00004e0 c35d 9090 4855 e589 ecbf 4005 e800 feee
00004f0 ffff c35d 9090 9090 9090 9090 9090 9090
0000500 c3f3 6666 6666 2e66 1f0f 0084 0000 0000
0000510 8948 246c 4cd8 6489 e024 8d48 ab2d 2001
0000520 4c00 258d 01a4 0020 894c 246c 4ce8 7489
0000530 f024 894c 247c 48f8 5c89 d024 8348 38ec
0000540 294c 41e5 fd89 8949 48f6 fdc1 4903 d789
0000550 63e8 fffe 48ff ed85 1c74 db31 1f0f 0040
0000560 894c 4cfa f689 8944 41ef 14ff 48dc c383
0000570 4801 eb39 ea72 8b48 245c 4808 6c8b 1024
0000580 8b4c 2464 4c18 6c8b 2024 8b4c 2474 4c28
0000590 7c8b 3024 8348 38c4 90c3 9090 9090 9090
00005a0 4855 e589 4853 ec83 4808 058b 0120 0020
00005b0 8348 fff8 1974 d0bb 6006 0f00 441f 0000
00005c0 8348 08eb d0ff 8b48 4803 f883 75ff 48f1
00005d0 c483 5b08 c35d 9090

Now if you are wondering what this is ^. Well that is what a hello world program in .c would look like in binary.

Many people asked me what I did to get this so here is a short description – compile a simple hello world C program. Do a hexdump on it and save its output. The open the elf a.out using readelf -a. Search for the .text section in the elf sections part, check its offset and tada you have the .text/code section with you.