IdeaMonk

thoughts, ideas, code and other things...

Wednesday, March 25, 2009

HN On my Wall!




Finally Hacker News has found a way on my wall. I hope there is nothing to debate about how addicting it can be to some people. And, how it keeps you coming back again and again for yet another amazing news. I'm one of those semi-addicts too, and I realize this ain't helping me with my productivity. Given that we hardly find time after college to do some fun projects here, HN becomes a great time-consumer. It's not HN's fault... we love the news :)

So, to keep me away form drooling over great things out there and diverting myself into thinking about 10 things at a time, I put HN too over my wall where I put up plans and stats for Project SpaceLock these days.

Have you to come across such realizations of addiction to HN ? Let me know what you did to save yourself from getting diverted by the awesome information overflow at HN.

Labels: ,

The Sixth Sense - Awesome Demo of Great Technology

Make sure you go and watch the TED talks - http://www.ted.com/talks/view/id/481 before you even take a look at anything on this blog... because that's something really superawesome (I won't disclose anything else about it :) ) to have a look at.
Enjoy!

Labels:

Tuesday, March 24, 2009

Finally implemented LINQ to SQL in SpaceLock's Web Interface

A typical ASP.NET MVC tutorial on Models talks about LINQ to SQL. Initially I had great troubles understanding this new syntax and style of LINQ as I am new to ASP.NET and C#. I had decided to write old ADO style connectivity routines for accessing the DB. The password validation code actually became too long and was almost broken, letting blank passwords pass through. No wonder it would be prone to SQL injections too.
While the tutorials from http://asp.net/mvc talks all about simple queries, nothing introduced me on how my classical SQL queries would look like in LINQ. I was looking for a LINQ equivalent of "SELECT password from users WHERE username==$user;"
Bumping around some YouTube videos I found a video called Using LINQ from David Bush. Clear, short and simple. And, with a little reference from 'LINQ for Visual C# 2008' (Apress) I was able to convert the whole SQL garbage to a better more organized LINQ query. See the difference -
// Old classical SQL code
public ActionResult DoLogin(string txtUser, string txtPass)
{
string password = "";
SqlConnection conn = new SqlConnection("Data Source=.\\SQLEXPRESS;AttachDbFilename=|DataDirectory|\\spacelockDB.mdf;Integrated Security=True;User Instance=True");
SqlDataReader rdr = null;

if (txtPass == "") txtPass = "!";

try
{
conn.Open();
}
catch
{
ViewData["message"] = "Failed to Create Connection to DB!";
return View("ShowLogin");
}
try
{
SqlCommand cmd = new SqlCommand("Select password from users where username='" + txtUser + "'", conn);
rdr = cmd.ExecuteReader();
if (rdr.Read())
{
password = (string)rdr.GetSqlString(0);
}
if (txtPass == password)
{
Session["LoggedIn"] = "True";
if (rdr != null)
rdr.Close();
if (conn != null)
conn.Close();
return RedirectToAction("Index");
}
else
{
ViewData["message"] = "Wrong Username or Password!";
if (rdr != null)
rdr.Close();
if (conn != null)
conn.Close();
return View("ShowLogin");
}

}
catch
{
ViewData["message"] = "Somethig Wrong with Query!";
return View("ShowLogin");
}
// Shorter, Safer, Organized LINQ code
public ActionResult DoLogin(string txtUser, string txtPass)
{
try
{
spaceDBDataContext spacelockDC = new spaceDBDataContext();
}
catch
{
ViewData["message"] = "Failed to Connect to DB [DataContext failed]!";
return View("ShowLogin");
}

var query = from user1 in spacelockDC.users where user1.username == txtUser select user1.password;

if (query.ToList().Count == 1)
{
// test the password
if (query.ToArray().Last() == txtPass)
{
// Successful Login
Session["LoggedIn"] = "True";
RedirectToAction("Index");
}
else
{
ViewData["message"] = "Wrong Username or Password!";
}
}
else
{
// nothing was selected - invalid username
ViewData["message"] = "Wrong Username or Password!";
}

return View("ShowLogin");
}

Labels: , , ,

PowerPoint for Web Mock-Ups

I had read a tip for web designers a few months back - Adobe Illustrator is good for creating mock-ups for a web apps. Well, I got another tip for all those short-cut hungry, time-savers out there - Use PowerPoint.
We had some 5 days left for submission of Project SpaceLock's architecture for Student2Business, and I had no idea how to show to my group, how the Web Interface would look like.
Enter Microsoft PowerPoint into the scene. All I did was layout the menus and a little background, that all, everything else was taken care by PowerPoint.
Don't believe me? have a look at the Mock-Ups yourself - http://www.slideshare.net/ideamonk/space-lock-web-ui

And then compare it to the finished user interface I did today -

Minor improvements are all that you will find. This is the first time I could complete a complete interface in just 4 hours, I usually take more that a day :O :P ;)
And guess what, mysteriously, I never had those famous nasty bugging IE6 design issues. It work's on a newly installed Windows XP too - http://spacelock.blogspot.com/2009/03/wow-that-worked-on-ie6-on-xp-too.html

The Lesson - Do look at PowerPoint too as an alternative for creating rapid prototypes and mocks for Web Interfaces.

Labels: , ,

17" MacBook Pro = A Car in India


MacBook Pro 17" Starts at $2799 with awesome features that make people like me go crazy.


But what Ratan Tata has done here in India makes me go even more crazier - Tata Nano, a car for everyone. With the same amount of money you decided to put in a MacBook Pro, you could have your own 4 wheels on the street and speed up to whereever you wish to go! Isn't that amazing. You choose!

Labels:

Speed issues with ASP.NET & Firefox

Developing the Web Interface for Project SpaceLock, I had a really hard time watching Firefox act slow with ASP.NET Development Server. While on one of the ASP.NET developer's forum bluemonde says - "FF is a piece of crap. I got really pissed off by watching it loading/refreshing for about at least 30 seconds on every click on the features of the site."
Did you call FF a piece of crap?! How about IE then, you can find plenty of criticism of older IEs.
Well, whatever, the point is you must get rid of this speed issue before you start testing your web app on Firefox and crib about its speed. You can find loads of articles on how to resolve this. I used the simplest one on JP's CodePoerty blog. Here are some more to look upon -
Don't forget to give
  • netsh interface tcp set global autotuninglevel=disabled
over your cmd with Administrative privileges. Happy coding.

Labels:

IE7 : Confusing UI when effects are gone


Well what wrong did I do if I disabled all the awesomeness of Aero and Themes in Windows Vista. Thats what I get to see in Tools>>InternetOptions>>[Delete] dialog of IE7. Isn't that a perfect example of a confusing UI. Now when most of the people, when done with 'Delete Browsing History', would be clicking the [OK] button in the [OK][Cancel][Apply] Group below. The efforts would end in a useless beep as the [OK] belongs to the dialog below it.
The 'Delete Browsing History' dialog is so uniform that most of us would be getting confused over this. And the [Delete all...][Close] group of buttons highlighted above adjust souniformly with the UI that people won't even pay attention to the [Close] button there unless you're used to clicking [X] unlike me.

Labels:

Sunday, March 22, 2009

The 64-32 bits issues in Visual Studio 2008 Express

I remember having a hard time fighting 64 and 32 bit issues while testing emgu.CV last month for Project SpaceLock. Final conclusion was to recompile OpenCV for 64-bits and then we had class tests and T2 @ college, due to which issue finally lost interest.
Well, it came up again today when Harsha sent a compiled example from emgu.CV for test on Vista 64 bit. Ooops, 'This program has stopped working...'. WTF, then I tried getting the sample working on my own VS2008 Express, but no success at all.
Google said many more developers are frustrated like you :) And finally an article on Bytes opened my eyes into a simple one-liner -
Well, the Express Edition of Visual Studio 2008 doesn't let you choose the target platform for your build. What I mean here is that if you're on a 64 bit machine with Vista-64, you won't be finding any drop-down in Project Properties to help you change the target.

Jon Skeet [C# MVP] has an interesting solution:
In your .csproj file, just make the changes shown in bold
<PlatformTargetelement >
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' ==
'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<PlatformTarget>x86</PlatformTarget>
</PropertyGroup>
>
That's all! for my version of VS2008 Express things look like this after the change-
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<PlatformTarget>x86</PlatformTarget>
</PropertyGroup>

Just below that, you've the configuration for Release version, add the PlatformTarget tag there too.

So, we would be maintaing all the modules of SpaceLock with x86 as target for now. Since the Emgu.CV & OpenCV binaries we have are in 32 bit, it would be wise and quicky to do this.

Labels: , ,

Friday, March 20, 2009

Gravity in 2d Games

mariojump


I always wished to know how exactly do creators Mario, Contra and Kirby (Specially this one) program gravity. Having done with the s = ut + 0.5 * at^2 and such forumulae, I haven't yet made a perfect framework for simple gravity physics, bounces and collision reactions. But, here is an article from The Science Creative Quarterly - link that really satisfies me with a historic look and clever analysis of the gravity in Mario.

Some more places to checkout for game physics-

http://wiki.slembcke.net/main/published/Chipmunk
http://www.box2d.org/
http://www.harveycartel.org/metanet/tutorials.html
http://www.codeplex.com/FarseerPhysics -- good for .NET developers

.

Labels: ,

Monday, March 09, 2009

Identification Simplified - An Introduction to Biometrics

Every semester in ASE, Bangalore, we end up creating something nice out of the gigantic mountain of information called the internet. That's not all, we do some real ground work too, as in the 3rd semesters English project where we explored the Mobile Retail Market through interviews and surveys.
This semester the task was much more fun filled and little more related to technology :). We had a larger, diverse group (me, soundar, kittika, bawa, doll, sastry n srikanth) to work with. A mess of time to manage, a jungle of information to organize and little cheap competition to beat off!
It was "Fun" as I would like to remember it. Cracking jokes and discussing friends episodes (psst! I don't watch friends) was all that we did. Little did we realize that, we came up with a nice introduction to Biometrics.
So here it is... addition of another Biometrics presentation to the internet (mountain of information), with a quantum of awesomeness.

Labels: , , ,

Sunday, March 08, 2009

The GW of GW-BASIC

After a wait of 9 years, I came to know what GW stands for, in GW-BASIC (my first programming language). Some teacher had heard a rumour in Modern School, Lucknow that GW stands for "GeeeWheee's". I used to wonder who could've been named GeeeWeee by his parents. Little did I know about internet then in the year 2000, nor did I search for it in the last 9 years.
I just happened to drop at one of these links at HN - http://www.classiccmp.org/pipermail/cctech/2005-April/042999.html
GW actually stands for its creator - Gregory Whitten, and also for Gee-Whiz and not some GeeeWeee. Woah! words do change when they travel across continents!
Now Gregory Whitten is indeed someone whom you would've called God back then! Seriously go ahead and read why so...
GW @ Wikipedia
GW @ RiskWaters
.

Labels: ,

Saturday, March 07, 2009

Lessons @ Failed Mooshak attempt

Whats in an attempt? A lesson of course. By now wandering over .edu sites you must've been through urls that look like http://domain.edu/~username/
I always wondered who sets these folders? Do they make a separate directory for everyone in /var/www/ or is it script that they run time to time ?
Well, it turned out to be another mod for Apache, suitably named userdir. Here's how to enable that -
# a2enmod userdir
Now in Ubuntu, don't confuse the 'Public' folder under your home to work. You can solve it using two ways -
1. You create a folder called "public_html" and place your stuff there.
or
2. You modify the /etc/apache2/mods-enabled/userdir.conf file to suit the 'Public' folder -
<IfModule mod_userdir.c>
UserDir public_html
UserDir disabled root

<Directory /home/*/Public>
AllowOverride FileInfo AuthConfig Limit Indexes
Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec
<Limit GET POST OPTIONS>
Order allow,deny
Allow from all
</Limit>
<LimitExcept GET POST OPTIONS>
Order deny,allow
Deny from all
</LimitExcept>
</Directory>
</IfModule>
and there you got... hit it - http://127.0.0.1/~<username>
Maybe now installing Mooshak would make some sense.

... after 20 minutes ...

Mooshak seems to be installed but http://127.0.0.1/~mooshak/cgi-bin/execute page shows the whole TCL script instead of executing it. Now thats too much for the night... I guess something went wrong with file permissions
:$

... after 10 minutes ...

Hit me with a pan on head... I was trying to make the latest unstable version work >:#
One must be careful with alpha, betas and nightlie's in the world of Tux. http://mooshak.dcc.fc.up.pt/download/mooshak-1.4.3.tgz -- a new food for thought.

... after 5 minutes ...

Mooshak-1.4.3 installed cleanly but only after a small patch in the 'install' script -
For Ubuntu 8.10 you should try changing like 148 into -
set fd [ open "| /usr/bin/lsof" ]
Well this does install successfully, but you still keep getting the code view of http://127.0.0.1/~mooshak/cgi-bin/execute instead of getting the script run in background. Chaning permissions doesn't help, tried 777, 755 everything possible.
... too much for today !

.

Labels: ,

Failed Mooshak installation attempts on A Fresh Ubuntu Desktop 8.10

I've gotta be playing with mooshak's UI soon. The first step - installing it.
I'm referring a blog entry by a Artur Martins (I hope I'm not wrong about his name, the about section is in French and I guess the name isnt mentioned) , where he installed it on a fresh Debian Etch.
As for my LAMP setup - here's how I've set it up.

#1 - the requirements
sudo aptitude install tcl apache2 xsltproc lpr rsync gcc libxml2-utils

#2 - the installation
% tar xzf mooshak-version.tgz
% cd mooshak-version
% su
# ./install

and... I get the following
couldn't execute "/usr/sbin/lsof": no such file or directory
while executing
"open "| /usr/sbin/lsof" "
(procedure "check_apache_modules" line 9)
invoked from within
"check_apache_modules"
(procedure "check_software" line 12)
invoked from within

By a quick check on 'lsof', I figure out that there's nothing like /usr/sbin/lsof. But, there does exist a /usr/bin/lsof.
So, our line 148 of the 'install' script becomes -
set fd [ open "| /usr/bin/lsof" ]

from
set fd [ open "| /usr/sbin/lsof" ]

And... there I go, straight into the pitfall of questions - "what went wrong? Couldn't it be a little simpler? ...", arising from my terminal -
root@research:/home/ideamonk/Desktop/mooshak-1.5a4# ./install
Missing Apache module: userdir
to install it in Mandiva: urpmi apache-mod_userdir
Missing Apache module: suexec
to install it in Mandiva: urpmi apache-mod_suexec

... a coffee break...

Reading the 4th step in Artur's tutorial I realized that I need to enable some mods in Apache. Here you go -
# a2enmod userdir
That isn't enough, we need 'suexec' module too, I guess that would be -
# a2enmod suexec
Enabling module suexec.
Run '/etc/init.d/apache2 restart' to activate new configuration!

Now Reload you Apache -
# /etc/init.d/apache2 reload

Lets try again -
root@research:/home/ideamonk/Desktop/mooshak-1.5a4# ./install


Woah, this is overflow of errors, my terminal scrolls at great pace with things like -
tar: data/configs/flags/pr/.data.tcl: Warning: Cannot stat: No such file or directory
tar: data/configs/flags/pr/pr.png: Warning: Cannot stat: No such file or directory
tar: data/configs/flags/pt: Warning: Cannot stat: No such file or directory
tar: data/configs/flags/pt/.class.tcl: Warning: Cannot stat: No such file or directory
tar: data/configs/flags/pt/.data.tcl: Warning: Cannot stat: No such file or directory
make[1]: Entering directory `/home/mooshak/bin/SafeExec'
gcc -c error.c -Wall -ansi -pedantic
gcc -c safe.c -Wall -ansi -pedantic
gcc -o os-detect os-detect.c -Wall -ansi -pedantic
gcc -c safeexec.c `./os-detect` -Wall -ansi -pedantic
gcc -o safeexec error.o safeexec.o safe.o -Wall -ansi -pedantic
make[1]: Leaving directory `/home/mooshak/bin/SafeExec'
cp SafeExec/safeexec .
chmod u+s,o+x safeexec
pass.c: In function ‘main’:
pass.c:55: warning: format not a string literal and no format arguments
pass.c:57: warning: format not a string literal and no format arguments
done
connecting to host research. ... couldn't open socket: host is unreachable
connecting to host localhost ... connected!
could not find user name in the output of 'info'


I think I should spend more time on mooshak documents and READMEs. That's what they say - "We read manuals when things fail to work." :)

Good evening.

Labels: ,

Setting up AMP of LAMP on Ubuntu

Well, I've already got Linux as Ubuntu 8.10. What remains to setup a web-dev environment, is the AMP of LAMP(Linux Apache MySQL PHP) bundle.
That would help me a lot as I plan to make mooshak (a programming contest system) better. Even otherwise, I could not avoid getting face to face with LAMP. Enough of one-click XAMPPs, when we will setup Sangam (a wordpress blog for events @ college), LAMP will bring the light in that useless Sun Microsystem's dabba :P
Anyways so how does one get the LAMP stack over Ubuntu Desktop Edition?
Well here are some options -
LAMP Setup Guide

Ubuntu + LAMP for newbies

Here is something much better than those one-by-one steps -
$ sudo apt-get install apache2 php5-mysql libapache2-mod-php5 mysql-server
That's from the FOSSwire tutorial, thanks to Peter Upfold for keeping it short n simple. All it took was 45 minutes for downloads and done! Here it is - result of one-line install -
Happy lightening your Ubuntu with LAMP :P
.

Labels: ,