Saturday, April 21, 2007

A Simple Motor, Super Fun

A cool motor using just a copper wire, a battery and a magnet. link (via).



Myopic view of , ,

Wednesday, April 18, 2007

A story of VNC and RDP

I have a laptop and a PC at work. The laptop has a docking station that allows me to have a dual monitor setup. So, I connected the Monitor from my PC to the docking station and started using a dual monitor setup.



As expected, the productivity gains by having a dual monitor setup is great, but my PC lost out.



For a couple of months, I stopped using my PC and started using my Laptop for nearly everything. But its not an ideal situation. Builds, large downloads etc. are best on a PC because I can just lock the PC and let it run in the background. Whereas on a laptop, I usually hibernate the laptop when I go home and so, any builds or downloads will stall.



I decided to setup VNC between the two today. I used TightVNC. However, I found that the refresh rate pretty much sucks. Given that the two are just a few feet apart, and on the same network, I expected it to be nearly realtime.



A colleague suggested that I use RDP instead. I tried it out. Its amazing! The refresh rate is realtime and it looks like I'm using the PC itself. Plus, it allows me to run it on my second monitor. So, I can have applications from both my PC and my laptop on the second monitor and there is really no way to figure out if they are from the PC or the laptop.



VNC is pretty bad when it comes to running on a second monitor. If you go "full screen", the server display disappears and you are back to the extended desktop from the laptop.



All said and done, for this kind of setup, RDP is really cool. VNC has its uses especially if for multiple connections, heterogeneous environments etc. Coding Horror has an excellent comparision of the two here.



Myopic view of ,

Sunday, April 15, 2007

Lua: Hello Mundo

The C API in Programming in Lua does not have a Hello World program. In addition, if you try to follow the example, and compile your code, the program crashes and displays the following
PANIC: unprotected error in call to Lua API (no calling environment)
So, I went to the Lua Users Wiki and found some tutorials but still no "hello world" program. So, here it is below

#include <stdio.h>
#include <lua.h>
#include <lauxlib.h>
#include <lualib.h>

int main(int argc, char* argv[])
{
char buff[] = "print(\"hello world\")";
int error;
lua_State *L = lua_open();

luaL_openlibs(L);

error = luaL_loadbuffer(L, buff, strlen(buff), "line") ||
lua_pcall(L, 0, 0, 0);

if(error)
{
printf("ERROR: %s", lua_tostring(L, -1));
lua_pop(L, 1);
}

lua_close(L);

return 0;
}
The code itself is self explanatory and the API interface is very interesting. A stack based approach to pass information to/from C from/to lua.

Myopic view of

Saturday, April 14, 2007

Excellent article on Chicken Scheme

This is really a great article on Scheme. Have a look at the linked articles, they are equally good. I need to give Chicken Scheme a try soon!



Myopic view of

Monday, April 09, 2007

Great site about vim

I use VIM a lot and its almost down to me being unable to code without VIM. This list is really cool! Plenty of tips that will help both rookies and veterans.



I particularly liked the tip about writing to a shell using :w !sh (or in the case of winxp :w !cmd). Its a really cool way of renaming files!



Myopic view of

Tuesday, April 03, 2007

Parameter Passing in C

A favorite question that a friend asks in interviews is related to the usage of a stack in C. His question to the poor sod on the other side is - if a function does not return, what could be some of the reasons?



Naturally, some of the answers are

1. There's an infinite while loop inside

2. The function is recursive and does not have a base result

but the answer that my friend looks for is

3. The return address on the stack has been corrupted.



The funny thing is - the C99 Standard does not even mention the word "stack" anywhere.

I asked a question about parameter passing on comp.lang.c and everyone agrees.



Its time to correct my friend!



Myopic view of ,