Monday, January 30, 2006

emacs

I was a vim user. But i always wanted to switch to emacs. I ve heard that vim can do whatever emacs can. Anyway .. after i started exploring lisp, i heard from lisp community that how good emacs was. So i bought "Learning GNU Emacs" in the hope that one day i will learn it. I use command prompt (windows) quite often in my office. One thing that bothered me was running so many command prompts and switching between those. So for all those ppl who suffer these things, im going to write how to use emacs. Start using it. Get the installation from here (windows).
After extracting, run addpm.exe from bin.

note:
C means Ctrl and M means Alt. So C-x means pressing Ctrl + x. C-c C-x means pressing Ctrl + c + x (ie hold Ctrl and type c and x). C-c x means Ctrl + c then release Ctrl, press c

Useful Commands

Opening a file - C-x C-f
A prompt comes below (near status bar) asking for file. you can use TAB for navigating directories or files.
Quitting a Command - C-g
Often you start typing some command and want to quit (ie escaping .. note ESC doesnt work that way). Use this.
For eg. you wanted to open file and did C-x but but you want to cancel it. do a C-g
Quitting emacs - C-x C-c
Saving a file - C-x s
Saving to another file (Save As) - C-x C-w
Saving all opened files (see buffers) - C-x C-s
Windows Commands
Emacs can open many windows inside it. Often it happens that some command or command completion opens a new window and your window splits. This will be annoying in the beginning. Use the commands below to navigate windows.

Going to other window - C-x o
Maximizing current window (current means where cursor is) - C-x 1
Splitting current window - C-x 2
Note that if you open new file after this, file will be opened in that window.
Splitting current window Vertically - C-x 3
See that C-x 2 opens window horizontally. Also you can use this and previous command inside a subwindow also.

Buffers
Buffers represent all the open files and buffers not connected to files ;). If you are using the GUI version, you can see the buffers in the menubar. You can switch to the buffers from there.
Going to another Buffer - C-x b
Press enter. This will go to the previously used buffer
Listing Buffers - C-x C-b (see the difference between previous and this command. In previous you needed to release Ctrl after x was pressed, and in this you need to use Ctrl for both x and b)
This will open another window listing all the buffers. To move to that window use C-x o, or use mouse. You can navigate through lines using 'n' and 'p' (next and previous .. You can use C-n instead of downarrow or C-p instead of uparrow. In Buffer List you need not use C-n, instead you can use n itself .. similarly for p). To select any buffer you can press '1'. This will make that buffer in a maximized window.
There are some other useful things to do in this buffer list. Like if you want to delete some buffers press 'd'. A 'D' will come next to that buffer. To undo anything press 'u'. Finally to execute these press x.

Closing a buffer - C-x k
Press enter. To close many buffers see above

Editing Commands.
This section will represent all the basic things like cut, copy, search etc.

Up Arrow alternative - C-p
Down Arrow alternative - C-n
Left Arrow alternative - C-b
Right Arrow alternative - C-f
(i suggest to use these once you get comfortable with emacs, otherwise all these will garble your brain)
Refreshing screen with current line in middle - C-l

Moving to start of line - C-a
Moving to end of line - C-e
Moving to start of file - M-< Moving to end of file - M->
(use shift key for '<' or '>')
Selecting some text (for copying or deleting).
Use C-space for setting a mark. Use arrow keys (or alternatives) to move to the location till you want the text to be selected. (By default it will not show selected region highlighted. See using .emacs file (below) to how to change the behaviour)

Once you have selected your text use below commands for copying, pasting etc
Copying Text - M-w
Cutting Text - C-w
Note that C and M (ctrl and alt) have many similarities in commands
Pasting Text - C-y (this is called yanking. in vim teminology yank means copy, but here it means paste)
Undo - C-/ or C-x u

Incremental search - C-s
Incremental search backwards - C-r
(note use C-s or C-r multiple times to find previous thing)
Ordinary Search - C-s enter

Running any command - M-x
I heard you can run any command using this. Type M-x and press TAB to see various commands. One example would be killing current buffer by M-x kill-buffer. Renaming buffer by M-x rename-buffer

Running command prompt or shell - M-x shell
enjoy. you can rename the shell to some other thing using M-x rename-buffer, and open as many shells as you can
Previous/Next commands in shell - M-p and M-n

Telnet - windows telnet doesnt work in shell. You need to dowload say jtelnet
(a java app). put the jar in CLASSPATH, and run
java thor.app.tenet.
One good thing is autocompletion of directory/files work probably because in shell.

.emacs file
In *nix .emacs resides in your home. in windows if you do a default installation, i think it takes from C:\. See the windows installation faq. Note that in windows it is named _emacs not .emacs (windows wont allow you to).
You can highlight the selected region by appending this in your emacs file
(transient-mark-mode t)
You can use syntax highlighting always by using
(cond ((fboundp 'global-font-lock-mode) (global-font-lock-mode t)
(setq font-lock-maximum-decoration t)))


Im a little bit tired now (no breakfast and lunch) .. if you want anything else do comment, i will update

Wednesday, January 25, 2006

rant

After all the comfort i had, im finally moving out of campus. New project, new manager, new place, new everything. I'll be moving to nearby location where neo was earlier.. slightly depressing. Since its last day in campus, we went outside for lunch. It was a good restaurant .. we had crab, squid, prawns and whatnot .. quite a feast.

I saw doom on monday .. it was ok. At least someone liked it.


Its a good four day weekend coming .. and am planning to watch the videos (around 10GB of divx) of sicp (book is available online). If you are a computer science student, do watch/read it. This is what they teach in MIT

Friday, January 20, 2006

garbage

Occasionally i go through python dev mailing list for interesting things. Today i came across this
where Guido says
>> FYI: Real libreadline is GPL, and rms made a point of forcing
>> (Aladdin-licensed) Ghostscript to remove stanzas from the Makefile
>> that allowed linking to it as a user option. Ie, this particular pain
>> in the neck is deliberate FSF policy, to encourage use of the GPL.

>Can we just all agree that RMS is an asshole now? Bah.

I respect both RMS and Guido and its funny how Guido doesnt like RMS. Another one here
"Citing RMS's insanity is a great way to get my blood steaming." --GvR

I remeber Guido getting an award from FSF. Some links 1 2.

Long before when ppl where using Tcl as glue language, RMS wanted to get a real language(he didnt like Tcl), Python was suggested. I think it was dropped as it was not under GPL. They set out to write Guile. I wonder where python would have been if it was chosen ..

Thursday, January 19, 2006

Zinda

Last week my original intention was to watch the movie Zinda, which ended up with collectivechaos. I felt the need even more so me and my friend sneaked out of the office yesterday at 3:30 to watch Zinda. nowrunning showed the move time as 4:40pm in PVR. We reached PVR only to find out that it had already started at 4:10. Since the website usually doesnt go wrong, we checked other classes and needless to say, it was there in gold class. The tickets in gold class will cost you 500Rs. We felt dumb to leave after all these efforts and decided to watch it from gold class. Out of the 500, you can claim 150 for food (i bought a 150Rs chicken roll .. wonder there was any chicken in it). The seat was great with buttons to adjust the positioning. You can make it a bed .. anything.


Coming to the movie .. well it was good. I always like dull colored movies ;). John Abraham was great.. and so was his hair. I remembered seeing a particular fight sequence in some movie (i think Zeus got it sometime back) .. and yes it seems Zinda is a ripoff of oldboy. Anyway good going Sanjay Gupta.

updtate:
My friend forwarded me an article on rediff
What i want say to these kind of people is just to shut the fuck up. If you dont like the idea .. dont watch it. Im tired of watching the silly bollywood movies. Zinda was an entertaining movie and i liked it. If its copied from somewhere, well i say it has been copied good. Without Zinda, i would have never came to know about oldboy or its concept. So its much better than watching nothing. All you pathetic critics out there .. eat shit and die!

Monday, January 16, 2006

spring summer fall winter ... aah crap

After one day of procrastinating over going for a movie, we set out yesterday for an ambitious goal of obtaining tickets from pvr on a sunday evening. It ended up with me, prashant, his friend and his friend's friend going for an "art movie" as i would call it (note: except for me, all others are regulars). There are a bunch of people called collectivechaos conducting this. Neo and Zeus .. you miss this crap :D
So what was the movie? .. it was called spring, summer, fall, winter...and spring. Here is my rather intellectual understanding of the movie


master and student - student harass animals - master punishes - student grows, so does master - girl comes for treatment - student screws girl - student screws girl multiple times - master sends girl away since she is recovered (of course because of screwing) - student runs away to find girl - girl runs away with another man - student kills girl - student returns - master punishes student - detectives come to catch student - student taken - master commits suicide (to a snake :? whatever) - student returns - student repents - lady leaves boy to student - lady dies - student the new master, boy the new student - loop

That would quite sum it up. Anyway i liked it and might go for it again. Hopefully no one from collectivechaos reads this blog, lest i might be burned alive!

Thursday, January 05, 2006

reverend blogs

reverend has a blog. He also has a site. Read his "Shadows in John Carmack's next engine" post.
I installed Quake4 in my work machine and it didnt work :( . Then i installed it in my laptop .. and it works!! . The graphics is pathetic, but playable. I didnt find any single player deathmatch, did they remove it? (i installed demo)

Tuesday, December 27, 2005

Who are You?



You scored as James Bond, Agent 007. James Bond is MI6's best agent, a suave, sophisticated super spy with charm, cunning, and a license's to kill. He doesn't care about rules or regulations and somewhat amoral. He does care about saving humanity though, as well as the beautiful women who fill his world. Bond has expensive tastes, a wide knowledge of many subjects, and his usually armed with a clever gadget and an appropriate one-liner.

James Bond, Agent 007


75%

Batman, the Dark Knight


71%

Lara Croft


63%

The Terminator


63%

Indiana Jones


63%

Neo, the "One"


58%

William Wallace


54%

El Zorro


42%

The Amazing Spider-Man


33%

Maximus


33%

Captain Jack Sparrow


33%

Which Action Hero Would You Be? v. 2.0
created with QuizFarm.com

Friday, December 23, 2005

Guido Hired

Wow .. Google hired Guido Van Rossum!!! see the news here
Ive been wondering when this will happen .. Hope this will fast forward python development.

Thursday, December 22, 2005

As Good As It Gets

I saw As Good As It Gets . Its a good movie. I loved the scene where he looses the dog and starts playing piano and then laughs at himself saying "for a dog". And yes how can you forget "You make me wanna be a better man" dialogue.


Monday, December 19, 2005

Dog

Dog in the house
buhahahaa

world is my loo


hydraulically pressed fake bone and joy


wine? .. hmm


better off with milk


closeup


yum .. sudoku

Not named it yet, i have suggested the name Schrödinger

Wednesday, December 07, 2005

PathFinding 2

I had earlier promised of explaining pathfinding through obstacles. Well i just wrote a quick applet to show it (using astar algorithm). Unfortunately its time for me to leave, so will explain later :).
Use
CTRL + left click to set predator
ALT + left click to set prey
click and drag to create walls
right click to solve

To clear use ALT + right click

yeah, i know that i should not be a ui programmer

Tuesday, November 29, 2005

Friday, November 11, 2005

My Desktop


Yup .. thats Carmack's picture on the wall ... if you need the wallpaper get it here

and backside
and more

thats a fountain .. and has a habitat of its own .. i hear frog sometimes

Wednesday, November 09, 2005

Thursday, November 03, 2005

Matrix Season

Looks like everyone is writing on matrix .. neo wrote The Awakening, Rakesh wrote pills ..
and here is a funny one by Gopal . The thing about toilet cleaner is too funny :D

"And Nemo (Gordon Everyman) is offered two drinks - a red one and a blue one. The red one is cranberry juice and the blue one is toilet cleaner - sort of hammers down into your head that There is no Choice."

Carmack on Doom Movie

This is what John Carmack has to say about Doom Movie

I had fairly low expectations, and there were even some plans in palce to guide me away from any press after the premier if I didn't like the movie, so I wouldn't say something "unproductive", but I was pleasantly surprised.

No, it isn't an oscar movie, but it definitely isn't Super Mario Brothers / Street Fighter / Double Dragon.

I do wish they had kept the true satanic / hellish theme, but I think they did a credible job with their alternate direction.

John Carmack


link

Tuesday, October 25, 2005

My new comp

I bought my 3rd comp. This time, its a laptop. An Acer TravelMate 2410 (this was the cheapest of all). I used to think laptops were waste, it still is in some sense .. with that money, i could have gone for a much better desktop system. But laptops have their own advantages .. mainly for me, it means i could read and rarely program from my bed, while watching tv etc :)

Here is the config ..
Intel Celeron M 360 (some 1.4 or 1.6GHz, forgot)
256MB Ram, 40GB Harddisk, 15" screen and a bunch of other crap ..

I always wanted a small laptop (a 12" .. it looks so cool), but unfortunately i got a 15" (as i said, i went for the cheapest one) .. its slightly bigger, and well, doesnt look good on lap. Also screen is pathetic (i didnt notice the laptop screens much before this) .. the laptop screen tends to have a bluish tint with a little bit of gamma.. (i checked with the thinkpad here in office)

It came with some Lupus linux (hell it didnt even have GUI) .. i tried installing Fedora Core, but its identifying as VESA .. i need to find the proper drivers ..

Graphics is pretty ok .. it gives around 80fps in 640x480 quake3 and is playable (40 fps i guess) in 1024x728 with high settings .. but again, the screen makes it pathetic to play with (it has upto 128MB shared mem)

All in all its an okay system, comparing the price.. it cost me 32k with carry bag (damn im bankrupt again) ..


Friday, October 14, 2005

Lisp

I am learning Lisp. Why and how, i will tell later. But one thing that struck me while learning is how common Python and Lisp are. I will now present some Python/Lisp snippets. If you can read Python, you sure can read Lisp.

Here is a code for factorial in Python

def factorial(n):
if n == 0:
return 1
else:
return n * factorial(n - 1)

Now code in Lisp

(defun factorial (n)
(if (= n 0)
1
(* n (factorial (- n 1)))))


In Lisp, operators come first in the list (prefix)

so in Python if you say
(2 + 3)
it is
(+ 2 3)
in Lisp.
Python:
(2 + 3 + 4 + 5)

Lisp:
(+ 2 3 4 5)


Just assume all those paranthesis are not there. You will find it almost like Python
Here is the Lisp version with some paranthesis removed


defun factorial (n)
if (= n 0)
1
* n factorial (- n 1)


How hard is that :)

Long back ago, when i was at the peak of Python craze, i saw Lisp and was quite frustrated by all its (). I then decided that i will not learn this language ever in my life. I was wrong. It seems there are many powerful features which Lisp has, and no other language has. So only way to learn is to learn it :)

Now here is the Python and Lisp version of Tower of Hanoi. Try figure
Python:


def towerOfHanoi (disks, fromp, to, spare):
if disks:
towerOfHanoi (disks[1:], fromp, spare, to)
print "Move %s from %s to %s" % (disks[0], fromp, to)
towerOfHanoi (disks[1:], spare, to, fromp)

towerOfHanoi ([3, 2, 1], 'a', 'b', 'c')


Lisp:


(defun towerOfHanoi (disks from to spare)
(unless (endp disks)
(towerOfHanoi (cdr disks) from spare to)
(format t "Move ~A from ~A to ~A~%" (car disks) from to)
(towerOfHanoi (cdr disks) spare to from)))

(towerOfHanoi '(3 2 1) 'a 'b 'c)

Thursday, September 29, 2005

Adrian Carmack Fired

It seems Adrian Carmack is fired from id. Read more

Friday, September 16, 2005

Language Integrated Query

Microsoft has come up with something called Language Integrated Query (LINQ) in C#3.0 (actually it is supported in CLR, so in VB.net also). This is too cool. What this means is that you will be able to write SQL kind of queries directly in the language. How this differs, well take an example in java where i try to query something

PreparedStatement pstmt = con.prepareStatement("select name from Employee");

Now the query is just a string. It doesnt have any compile time checking, say if you write mame instead of name, you will need to wait until runtime to find that error. (Not that this makes a big difference, because you should always write unit tests to verify your program parts).
Lets see how this is with C#3.0

Customers[] customers = ...

var q = from c in customers
where c.City == "London"
select new {c.CompanyName, c.Phone};



Now lets look at this in detail.

First, we see that whatever query we are writing is working on customer array. So the LINQ not only works with database, but with in memory collection, xml etc. So it is in fact "integrated" with language(C#), database, xml.

Second, we see that from comes before select unlike in SQL. (in sql you write
select foo from bar
not
from bar select foo
). Why this is so? well if you think about it the bar scope should actually come before foo. ie foo is a field in bar. so if you dont specify bar before foo, how the can say editor know about foo.

ie say you are writing in the ide

from bar select .. 
(and press ctrl + space)
you get all the fields in bar, because we specified bar before select.

if it was the other way around

select .. 
(press ctrl + space)
nobody has any idea on what object you are writing query .. (bar is still in your head)

So in C# they made from before select. You get intellisense in your query!


Third, we see something
new {c.CompanyName, c.Phone}
. what is this? well this is a new object which has fields CompanyName & Phone. You dont have to create a new class for it, it is anonymous.and the type of q is inferred.so if you say q. (ctrl + space), only CompanyName and Phone pops up. Well there are many more type inferencing going on with anonymous functions (lambda) etc .. all with compile time type checking. (well even though i love python with dynamic typing, intellisense is one thing which is the way to go).

I dont know how many lines of code are going to be reduced because of these new features.

From Anders Hejlsbergs video, i see a lot of things .. please do check it from here

Java is trailing behind C# .. they have good Generics support with reification, .. now this LINQ. All are looking so cool. It will be interesting to see how java catches up.
Talking about microsoft, there are tons of stuff they are coming up with ie7, sparkle... in this year's PDC .. see them at channel9

Update: covered in slashdot