Posts

Showing posts with the label programming

Running node.js on windows without using Cygwin

Finally node.js is available as a windows binary without requiring Cygwin to be installed. As of writing this post you can download the node.js binary 0.5.6 . Currently npm does not work with node.js on windows. You need to download and use ryppi.py instead of npm . It works similar to npm but requires python. To setup node.js first set the PATH and NODE_PATH to the where you have copied node.exe.              set PATH=%PATH%;c:\node              set NODE_PATH=c:\node It is better to set these environment variables in the System Properties so that you don't have to set these variables every time. Follow the following steps to do that. Right-click  Computer , and then click  Properties . Click the Advanced system settings in the left side bar. Click the  Advanced  tab. Click  Environment variables . Append the node path to the PATH variable Create a new variable...

Speed up your JavaScript

Image
This post is just for my own reference. Here are the slides and the video of the presentation by Nicholas Zakas. Goes into great detail in ways to improve the speed of your javascript code. Speed Up Your JavaScript View more presentations from Nicholas Zakas The article summarizes most of the points in the slides and video http://james.padolsey.com/javascript/zakas-javascript-performance-tips/

The best mobile development platform for hobbyist programmer - IV

The best mobile development platform for hobbyist programmer - I The best mobile development platform for hobbyist programmer - II The best mobile development platform for hobbyist programmer - III Over the last few years the whole mobile landscape has completely changed. Now the contenders have also changed. When I last wrote about the topic there was no SDK for the iPhone and Android had not launched. Since then the whole landscape has changed. iPhone is the king amongst the platforms. Android is a close second. J2ME is a platform which still goes unnoticed since its just not part of most new smartphones. The process to develop Windows Mobile apps has gone a complete transformation with a completely brand new way of developing apps. Symbian is in its last leg, Nokia will be moving to MeeGo soon enough. Palm development also changed completely with the launch of Web OS. If you plan to develop today here is how you can go about it. 1) iOS Development - SDK for iDevices 2) Android 3) P...

Getting song information from a shoutcast server

This is a very simple way to get the currently playing song information from the server. Append /7.html to the music stream. This will give out a HTML file with the following details. There is CSV information inside the body. Based on the position you can find the following information. 1. Current Listeners: 2. Status: 3. Peak Listeners: 4. Max Listeners: 5. Reported Listeners: 6. Bitrate: 7. Song Title: To see whats currently playing on Radio TeenTaal you can try http://91.121.155.39/7.html .

Force shoutcast server to send audio stream

This is something I had read about some 7 years back but had completely forgotten about it. Basically I was trying to get the audio stream from the shoutcast server in the browser. If you open the shoutcast url in the browser you will get a html page and not the audio stream. To force the audio stream use http://example.com:8032/;stream.mp3 the ;stream.mp3 in the end forces the server to send the audio stream. You don't even have to write ;stream.mp3 you just need to add a ; (semicolon) in the end. Hopefully next time around I am looking for it. I can read it here. I was looking for this info an year back but wasted quite a bit of time but could not figure it out.

COMET for Chirp User Streams - II

After almost giving up I finally figured out a way to use the Chirp User Streams . Not the best way to use it but I guess it just might work. Create a XHR request and abort it ever other minute. It will complete the request and make a new request. Try and keep the connection alive. This is something that facebook does in its chat. Thought there the connection is aborted by the server. In this case make sure that you abort and make the connection the very next second. It should be possible to use the same connection to reconnect to the server. But I have not tested it extensively to see how it will work in a real world situation. For now it works and hopefully when I again get to work on it I will write something more about how I use the ChirpUserStreams.

COMET for Chirp User Streams

Image
First there was AJAX and to give it company there was COMET . Incidentally both names of popular disinfectants in North America. In JavaScript AJAX allows the client to PULL information from the server and COMET is the technology where the server PUSHES down information to the client. I got interested in COMET after going through Chirp User Streams . Thinking it would be a trivial task to call a XHR and keep listening to it. In my mind I kept thinking that it would be stuck on readyState 3 and it will never get to 4. Since it would be stuck at 3 I could use a timer and after every few seconds keep checking for the change in length of xhr.responseText.length . Technically it should work like that.. BUT.. the way IE has implemented XHR it is not possible to check the responseText till it reaches 4. Which means that the request has timed out or ended. That somehow makes no sense at all. I figured out it was time to investigate and see how Facebook and GTalk were able to work on IE if i...

Moving from Basic Auth -> OAuth -> xAuth

Twitter will remove the option to use Basic Auth from June onwards and the only option left is OAuth. But the problem with OAuth is that its a UX nightmare to implement in a Desktop application. After trying to figure out how to use OAuth all day long I finally figured out that I was looking for xAuth all along. Cutting a long story short I found a blogpost which helped me get a hang of it. Using xAuth, an alternate OAuth from Twitter . Also found a little bit of help on the twitter wiki on using xAuth . Its quite simple to use once you get a hang of it. But since it mentions headers in most of the places I assumed HTTP headers but you need to provide all the parameters when you POST it to twitter. I have sent out a mail to enable xAuth on my account lets see how long that takes and I can finally start using xAuth instead of the cumbersome OAuth to log into twitter.

Dynamic GUI and console windows application

Running the same executable as a GUI as well as console application. This is one problem I had come across a few years back. But I soon realized that its decided while linking if an executable will be GUI or console application. But given the amount of time its been I thought of searching online and I came across this article " How do I write a program that can be run either as a console or a GUI application? ". It kinda had a solution but in the end its still better to have two separate executables. One for GUI apps and the other for console apps. After all these years Java also has two executables. java.exe for console apps and javaw.exe for GUI apps. There are two bytes in the executable file which tell the OS if the file is Console or GUI app. Change those bytes and you can run it as a console or GUI application. For more information about the PE format visit http://wotsit.org . Hopefully this is the first in the series and hopefully I will be writing more about it soon...

Wacking my brain with localStorage and globalStorage in Javascript

Most of the browsers these days allow you to store a lot of data instead of using cookies. I am still trying to make a library which will allow you to store data on the browser no matter if you have localStorage, globalStorage, flash or the good old cookies. The thing about using flash is that you need to wait for it to initilise and that is a little bit of a problem. I hope to release the library under the BSD license. Not sure if anyone would be interested, but I really need to get it done for fefoo .

Will silverlight make any impact on flash?

I was trying out Microsoft silverlight a few days back and compared to flash it actually rocks. Its light years ahead of flash with a choice of programming languages and the basic design. Also if Microsoft sends it out as an update it will be in at least 70%-80% of all machines in a few days time. Thats just one side of the story. Since most designers/developers who have mostly worked with flash would not want to change since there seems no valid reason to change. So probably Microsoft needs to make a killer application in silverlight that can really challenge flash. But given the kind of platform that silverlight is its not very difficult to build one. There is more to come on this topic as developers begin to see the technology and power of silverlight.

A very brief review of the javascript libraries

I've have never really liked any JavaScript library and i normally believe in writing my own code so that I know whats going on and where it is. But for a change with an open mind I began looking at the different JavaScript libraries that are available. I tried out the following. dojo ExtJS YUI JQuery prototype dojo This one is really extensive and tries to achieve anything and everything. It seems easy to grasp and I was able to get going in less than a few minutes. But given the fact that it is really extensive it also adds to the weight. I don't think I would be using the complete library in any of my projects but if used as a learning resource it can be really great. ExtJS This is one library I have seen from the very beginning I have always liked it. The toolkit is really professional looking and seems to fit the bill but the only hitch is the license, its under GPL3 . If you don't mind paying then you can get it with a commercial license. This is one of the best lib...

Killing two birds with one stone

The thing I am working on today is more like killing 5 birds with one stone. Like I wrote last week I started with Python , but due to the work load over the last two weeks I could not do much. This Friday I got an invitation to Google App Engine and the only language they support as of now is Python. This in a way pushed me into learning python. Last month I had written about a bridge for Facebook and Open Social applications. With many new things I devised a clever plan I have started off with a facebook application for the open social platform in python using the google app engine. That is 5 technologies covered in one single shot. I started with PyFacebook but, soon realized that the library urlib2 uses sockets and PyFacebook won't work for me. I could start with a new library or hack PyFacebook and since I am an expert in Python (with less than 2 days of experience) I resorted to hacking the PyFacebook library. I have never really programed in Python and the fact that the li...

Getting down and dirty with Python

I have spent the better part of this weekend getting down and dirty with python . Also I found the GUI library I was looking for in venster . Last night I was reading about the different GUI GUI development options available for Python. There are the the usual libraries like wxPython, GTK, QT, Tk, FLTK, Swing, SWT, Swing and .net forms. All of them are good but the main problem with most of them is that they are huge and the others which are small don't look or feel native. Out of all of them I like SWT but then again if I am going to use SWT then why not just use Java. Venster looks like a very good project but seems to be dead for the last 4 years and if I can get some time I might want to work on it. The library is tiny and does not add much weight to the over all deployment package. But then again its still my second day and I've barely scratched the surface. The tutorial I was using was a little sketchy about classes in python so I still need another reference for classe...

Finally learning Python

I've tried my hand with Python a couple of time but it could never really hold my interest. But over the last few years its matured a lot and its available on multiple platforms and also one of the only languages which seems to have a binding to nearly every new library that comes out. Lets see how far I go on this adventure. And for how long python will be able to hold my interest, will I go beyond the basic "hello world" programs.

Generating regular expression at runtime in javascript

I have never been good with regular expressions. I normally search for the regular expressions online and use it, I can never seem to get them into my brains. Lately I've been working on things where I've had to generate a regular expression at runtime. It is a trivial thing but I was unable to find it when I look for it. So in case you are looking for generating a regular expression at runtime this code snippet might help you out. var data = "This is a string and I want to replace all the a's"; var re = new RegExp("a", "ig"); alert(data.replace(re, "m")); This post is more like a reminder for me.

Open Social Container and my first Facebook Application

Its the last day of my easter vacations and five days of good work. I had initially planned to go out somewhere for these holidays but as nothing really worked out I ended up staying at home. So instead of wasting my time sleeping and watching TV (which I still ended up doing) I thought of finishing my ever growing list of personal projects. But instead of starting work on one of the pending projects I ended up starting yet another project. I searched around for an open social container and I found one but it was in Java and since I don't have any server which would allow me to host the project I ended up working on my own open social container. Well I worked on it for two days and it at least works with most of my samples I created for open social and also a few other gadgets. As of now its completely in JavaScript so in terms of security there is none to speak of, but by the end of it I did make a container and learned quite a lot. The code still looks way to hacked up to put on...

A better alternative to window.onload

This code can be used as a better alternative to window.onload . We use main as the function from where the execution begins. We also have a __app_started varible which tracks if main has been called so that it is not called more than once. Basically by this technique main gets called the moment body has been completed. If you use window.onload it waits till all the images and CSS have been loaded and in most case that can really be a while. var __app_started = false; if(document.addEventListener) document.addEventListener("DOMContentLoaded", main, false); else { document.write("<scr" + "ipt id=__ie_onload defer src=javascript:void(0)><\/scri" + "pt>"); var script = document.getElementById("__ie" + "_onlo" + "ad"); script.onreadystatechange = function() { if(this.readyState == "complete") main(); } } window.onload = main; // If all else fails function main() { ...

#include or include a file in javascript at runtime

I had written about require or #include in javascript and it works but sometimes you don't want it to be added it using DOM. This function uses DOM incase the body has been loaded or uses document.write to load the file. function $include(url) { if(document.body) { var script = document.createElement("script"); var head = document.getElementsByTagName('head').item(0); script.src = fileUrl; head.appendChild(script); } else document.write("<script type='text/javascript' src='" + url + "' ></sc" + "ript>"); } If you look carefully the name of the function is $include . It just makes it stand out other than that you could name it whatever you want. This just makes the code really clean and no more messy html files with 10 script tags to load all the files. It just makes life simpler if you have too many script files to load.

"Hello World" ruby and python on dreamhost

After having dropped all my plans for a vacation I have nothing better to do so I started with the stupid idea of trying to run different languages on my dreamhost account. Let me start with ruby first. Open up your favorite editor and copy paste the code below. Save it as testruby.cgi on your server. Change the permissions for that file to chmod 755 testruby.cgi . #!/usr/bin/env ruby require "cgi" cgi = CGI.new("html3") cgi.out("text/plain"){"Hello World"} If all goes well you should see hello world. I tested it here . Once you've tested it out you know that your account supports ruby. Now moving on to python. Copy paste the code below to a file testpython.py and change the permissions for that file to chmod 755 testpython.py . #!/usr/bin/env python import cgi field = cgi.FieldStorage() print "Content-Type: text/plain\n\n" print 'Hello, world!\n' If all goes well you should see hello world. Here is my python hello world...