It’s been a while

          0 votes
August 22nd, 2008

Yup, its been quite a while since I've posted anything. I got sick and also had some minor surgery that made me really weak and maybe a bit unproductive. Its been about a month since then and I'm finally starting to feel my strength again, mentally and physically so I hope to start blogging again soon :)

- Richard S.

Share/Save/Bookmark

iPhone Software Upgrade 2.0

          0 votes
July 12th, 2008

I just upgraded my iPhone to the latest system upgrade which is pretty much just like the old one with just a handful of new features. The biggest feature (to me) is the ability to add 3rd party products.

Of course you were able to do this before if you unlocked your phone but not too many people were making applications for it because unlocking your phone was kinda underground. Nevertheless now we officially got and now we got some cool apps to play with!

Here are my Top 5 Favorite Addons!

  1. Remote - While your iPhone/iPod is connected to your LAN you will be able to use it as a remote control to control your iTunes!
  2. AIM - Yup thats right! No more need for those annoying web based clients that were always laggy and annoying. AOL has made a decent AIM client for the iPhone for you to use. Its pretty standard and doesn't have features like pictures, voice chat, or etc but its gets job done.
  3. Evernote - I love to be able to access my data from anywhere, regardless of what it is. Evernote lets you take notes, pictures, voice memos, and more from your phone and syncs them up with their server which you can then access through your browser or through a desktop application (Windows / Mac). The basic free account gives you 40mb a month which should be enough but you have an option to upgrade.
  4. AOL Radio - Yup! Listen to your favorite online or favorite local radio stations without the need of an FM transmeter! Now I can listen to Frosty, Heidi, and Frank or Tom Lykis literally anywhere I am or listen to some up beat music when I hit the gym! (...yeah right)
  5. Movies - If the title isn't obvious enough, well this little app makes it very easy and convenient to find movie listings by theater or movie and you can skip the box office and purchase them directly through your iPhone.

While all that above is great and all there is one feature I was really looking forward to that doesn't quite work. If you wanted to connect to Outlook Exchange servers well you might be able to depending on your server setup but for some reason it won't work with my works exchange servers.

Anyways that will conclude this blog for now. If you would like to know more about whats new with the iPhone follow the link below. All these new goodies though are seriously making me consider upgrading the hardware as well so I can get on the 3G network.

Oh well enjoy!

Apple iPhone

PS: If you are afraid of upgrading your software because you have an unlocked iPhone don't worry about. I unlocked my phone as well and the upgrade process went smooth with no hick-ups as you might have experienced with previous 1.x upgrades. It will take a while but that is normal, just let it sit and go grab a snack or something.

Share/Save/Bookmark

Tune-Up Eclipse 3.4 with PDT 2

          0 votes
July 11th, 2008

If your one of those people like me who get excited when a new version of software comes out you put everything behind yourself rush right away to download it and install regardless of any new bugs it might bring. At first it was great but then the more you use it the more you notice things that aren't quite working right and a few gotchas here and there.

PHP Development Tools

You'll notice that you cannot open code declarations (F3) when any versions of PDT 1.0 - 2.0 Integration Build (as of this witting). However this bug is apparently fixed in the nightly build so go ahead and download that version of PDT to get it working... There is a download link below under My Setup...

Next, if you notice your IDE hang almost forever every time you start typing variables you can fix this by going to Windows -> Preferences -> PHP -> Editor -> Code Assist and un-checking Enable auto activation. This seems to be really laggy and extremely buggy even if you set the Auto activation delay higher. Usually you'll get the error below with this:

Problems During Content Assist

The good news is that you still get your code completion when you hit Ctrl + Space and it seems to come up a little faster.

The Right Runtime for the Job

During this hateful quest I decided to try out a few different IDEs. BEAs JRockit (now Oracle's) seem to have given me the best performance on Windows. I've heard good reports about IBMs JRE but since I'm not on a IBM platform they won't let me install it! If you're on linux I've also heard good things about IcedTea Java.

My Setup

Conclusion

Aside from what's listed above the only last bug I notice with PDT is the Path Variables settings not workgin (Window -> Preferences -> PHP -> Path Variables). That was useful feature for me in previous versions of PDT but it looks like they've got a few other ways not to define external sources for your project that will work for now.

Of course this is also all development so as time progresses these issues may all be resolved but you like to live on the bleeding edge like me then you might get cut as they say :) Oddly enough I notice much more better results with the same setup on my Mac :-P Mac owns!

Share/Save/Bookmark

Cutest dog/bear thing

          0 votes
July 8th, 2008

I was cleaning up my desktop and found this picture of the cutest little dog I've ever seen. I dunno where I found it from, googling or something but I can't find what's this dog called. It looks kinda like a teddybear but a dog?

Cutest Dog

If you know what this please add a comment or email me!

Share/Save/Bookmark

Run Ruby Code on Google App Engine!

          0 votes
July 7th, 2008

Oh wait what? Google App Engine is for Python you say? Ah yes that is correct but apparently this person named Why (not sure if that's his alias or his real name) has created a byte code decompiler which recompiles your Ruby code into Python code! Is that nutty or what?!?!

Of course this is far from stable and should only be done for fun but if you want to read about it here it is: Sneaking Ruby Through Google App Engine (and Other Strictly Python Places)

In theory you should be able to do this wherever Python code is ran, right?

Happy Hacking!

Share/Save/Bookmark

Compressing JavaScript … TO THE MAX!

          0 votes
July 6th, 2008

Here is the best recipe I've came up with so far to compress JavaScript. The goal here is to get our JavaScript file the smallest possible. In a nutshell, first we will obfuscate and then we "minify" it.

With obfuscation we'll convert all of our meaningless variables to the shortest meaningful variable needed. "Huh?" What I mean by that is basically all of our variables that we don't have access to or need, specifically variables within functions don't really need any meaning as long as they get the job done... per se... When we write code we name variables in a way so that they make sense to us, humans. There's obviously nothing wrong with that but on the computer's side of things they're just a set of instructions where the naming doesn't mean anything. totalPrice + tax = price means the same to a computer as foo + bar = result which means the same as _1 + _2 = X. We're going to use obfuscation to save space of our useless variable names.

Clarification: The variables aren't useless, their long names are.

After doing what we can with variables we then need to minify our script. This is very simple, just removing all useless white-space and line breaks. It may not sound like much but your web browser would also have an easier time parsing your code if it was all on one line.

The tools for the job

And walla! Go ahead and download these tools off their sites. For JSMin just download the C source code for now if you're on Mac or *nix but if you're on Windows they should have a zip file containing an .exe on the bottom of the page somewhere. For the prior, simply compile the source like so:


$ gcc -o jsmin jsmin.c

  1. Custom Rhino: This is what we'll use to obfuscate our JavaScript code. Custom Rhino is a modified version of Mozilla's Rhino JavaScript interpretor which has an obfuscation feature added to it.
  2. JSMin: And this would obviously be our minify tool! There are actually quite a few other tools that do the same thing JSMin does but I chose to use JSMin because its available in many programming languages. This is a plus for me because I love getting my hands dirty in other languages and it just works.

Doing It!

Lets get started with our ever so boring Hello World! test but because this project is so exciting it will make up for it! Right? Hehe anyways here goes our little JavaScript code, put this and the programs we've downloaded above all into one directory just for the sake of testing for now (you can organize them into somewhere more meaningful later) and save the JavaScript code as test.js:

var message = "Hello Richard!";
 
helloWorld = function(msg)
{
	var message = msg.toUpperCase();
	alert(message);
}
 
helloWorld(message);

Very simple. We got a global variable named message, and function named helloWorld. Now its time to pack this baby together! Open up a console window and lets do it step by step:

$ java -jar custom_rhino.jar -strict -1 -opt -c test.js > tmp.js

If you take a peek at tmp.js then Rhino should have generated this:

var message="Hello Richard!";
helloWorld=function(_1){
var _2=_1.toUpperCase();
alert(_2);
};
helloWorld(message);

What's really important to note here is that our global variable names remained the same and so did our function. The only code that is obfuscated is the code that means nothing to us anyways :-) ... Nothing in that we don't access it anyways.

Next we minify the code with JSMin:

$ ./jsmin < tmp.js > test_compressed.js

Our code should look like:

var message="Hello Richard!";helloWorld=function(_1){var _2=_1.toUpperCase();alert(_2);};helloWorld(message);

And walla! Isn't that beautiful! Of course the space savings isn't tremendous with this small script but I've tested it with Prototype v1.6.0.2 and it went from 123kb to 83kb! That's about a ~40% save right? Not so bad.

So now we've got our code obfuscated and compressed on the client end as much as possible. This should definitely help with transferring over all your JavaScript much faster and your browser should have an better time rendering it.

We can also eliminate the need for tmp.js and perform the above operation with one command:

$ java -jar custom_rhino.jar -strict -opt -1 -c test.js | ./jsmin > test_compressed.js

Conclusion

Well there you have it. Its also good to note to always start and end loops and conditions with opening and closing brackets even if you have those one liners for compatibilities sake. Your code should be packed for distribution when you are sure its at a stable state otherwise debugging can be problem and a headache fast.

If you want to take things further you can optimize your server end by adding gzip compression to Apache or whatever you use and also refactoring your code. The lesser try/catches would help as well.

Here are a few other tools:

  • Dojo Shrinksafe: An online compression tool made with Dojo's custom_rhino.jar.
  • Rhino: This is the homepage of the Rhino JavaScript interpreter that the Dojo developers extended to give obfuscation capabilities to.
  • Dean Edwards Packer: A pretty popular JavaScript packer. Source also available
  • Packer JavaScript in PHP: Same as the one above but made in PHP

Share/Save/Bookmark

Bitwise Configurations - Crash Course

          0 votes
July 3rd, 2008

Using bitwise configurations in software can have its advantages when you want to store a multiple configuration values within a single value. The only disadvantage (I see) with this technique is you cannot exactly query for a specific permission in your database if you are storing the configuration there but otherwise if that's not necessary it might be an advantage along with the fact of its simplicity.

Note: It might help if you have any knowledge of binary numbers but its not necessary.

Jumping Right In!

That's right! Its a crash course so lets just jump right in! With bitwise configurations each configuration is a number, but not just any number, they go by multiples of 2 starting from 1. For our example, I'm going to make up five configuration settings to play with that will determine my application's error settings. These can be anything of course. People sometimes use bitwise operations with permissions but anyways here we go...

ERROR_WARNING = 1
ERROR_CRITICAL = 2
ERROR_UNSUPPORTED = 4
ERROR_DEPRECATED = 8
ERROR_FATAL = 16

There we have our configuration, as you see each setting starts at 1 and goes up by multiples of 2.

So now lets say I want to configure my program to report all critical, deprecated, and fatal errors. That would simply be the sum of those configurations:

ERROR_SETTINGS = ERROR_CRITICAL[2] + ERROR_DEPRECATED[8] + ERROR_FATAL[16]

Usually when you configure *nix programs with something like this you don't use the + operator but instead a pipe, |:

ERROR_SETTINGS = ERROR_CRITICAL | ERROR_DEPRECATED | ERROR_FATAL

The above syntax is usually valid in most programming languages. At least Python, Java, C, and PHP off the top of my head. So now we have ERROR_SETTINGS equal to 26.

To check if we have a specific setting configured in ERROR_SETTINGS, such as ERROR_UNSUPPORTED we could simple do:

ERROR_SETTINGS & ERROR_UNSUPPORTED

That will return 0 because ERROR_UNSUPPORTED has no bits that match 26. To explain it further lets take our numbers and look at them at as binary numbers:

26 = 11010
4 = 100

As you see the 1st 0 from left needs to be 1 in order for 4 to match 26. So if our ERROR_SETTING included ERROR_UNSUPPORTED its value would 30 and its binary number 11110 thus 4 (binary 100) would match.

When testing if your configuration contains a certain setting using &, as long as it returns anything greater than 0 then your good! ... Otherwise its not part of the configuration.

Conclusion

I hope this crash course made sense to you. If you are still a little unclear how it works wikipedia has a thorough tutorial explaining how bitwise operations work and a good explanation of binary numbers.

Also, if you are programmer it sometimes might make sense to use bitwise operations to store configuration values because as we know, computers are mathematical machines and its what they do best. Its by far way less expensive to check if a configuration exists using the bitwise technique as opposed to storing your configurations in a list or dictionary and looping through them to check if what you are looking for exists.

Share/Save/Bookmark

Python and .NET playing together!

* * * * * 1 votes
June 27th, 2008

Intro

Lately my head has been up in the clouds playing around with a few languages, Python, C#, and Java (we'll get into Java later) as I usually do for fun and I thought how fun would it be to mix them!

Of course this is nothing new. There have been interpreters to mix and match them all you like for some time now and in this blog we'll focus on Python and .NET for now.

IronPython

IronPython is an implementation of the Python interpreter written completely in .NET. Being that it is written in .NET you can access all the .NET libraries with the interpreter and run it on any platform.

To run IronPython on any other than MS Windows (*nix, Mac, etc) you will need to install Mono. Mono provides the necessary software to run and develop .NET software on other platforms.

Note: The Mac package of Mono comes with IronPython. If you are on *nix you can probably find a package for your distro or have to compile it for yourself. If you are on MS Windows you can get the latest .NET run time from your Windows Update.

It takes two to tangle!

So after all that babble lets get started! Out of all the .NET languages I am currently most familiar with C# so I'm going to be taking some C# examples and showing you how to do them with Python using the IronPython interpreter which is invoked via the ipy command.

We'll start first with the ever so boring "Hello World" program.

In C# we would do something like this:

using System;
 
public class HelloWorld
{
	public static void Main()
	{
		Console.WriteLine("Hello Richard!");
	}
}

The above code should be extremely obvious, if not I suggest some polishing up of your C# skills.

Now with Python, I'm going to write the same exact thing (minus wrapping it in a class since its unnecessary with Python at this point) and I'm going to output "Hello Richard" using the same C# libraries:

from System import *
 
Console.WriteLine("Hello Richard")

That's it! An extremely simple 2 lines! Not bad huh? Of course that was cool but not something so useful.

All we've done was imported the System library into the current name space. We could have also done import System but then we would have had to write the whole System.Console.WriteLine() command. In some cases that might be useful if you don't want certain things to conflict.

Now lets do something a little more cool like interacting with a DLL created completely in .NET. If you want to know how to create a DLL file yourself then Google it but for now I'm going to take one already made.

For this example I'm going to use the MySQL .NET Connector and query some junk from my database.

Here would be the C# way (borrowed from here):

using System;
using System.Data;
using MySql.Data.MySqlClient;
 
public class Test
{
	public static void Main(string[] args)
	{
		string connectionString =
			"Server=localhost;" +
			"Database=test;" +
			"User ID=myuserid;" +
			"Password=mypassword;" +
			"Pooling=false";
 
		IDbConnection dbcon;
		dbcon = new MySqlConnection(connectionString);
		dbcon.Open();
		IDbCommand dbcmd = dbcon.CreateCommand();
		// requires a table to be created named employee
		// with columns firstname and lastname
		// such as,
		//        CREATE TABLE employee (
		//           firstname varchar(32),
		//           lastname varchar(32));
		string sql =
			"SELECT firstname, lastname " +
			"FROM employee";
		dbcmd.CommandText = sql;
		IDataReader reader = dbcmd.ExecuteReader();
		while(reader.Read()) {
			string FirstName = (string) reader["firstname"];
			string LastName = (string) reader["lastname"];
			Console.WriteLine("Name: " +
				FirstName + " " + LastName);
		}
		// clean up
		reader.Close();
		reader = null;
		dbcmd.Dispose();
		dbcmd = null;
		dbcon.Close();
		dbcon = null;
	}
}

Now, lets do this the Python way with the same rules as the last example; using the same C# libraries.

import clr
clr.AddReferenceToFile("MySql.Data.dll") # MySql.Data.dll must be located in the same directory as this script
 
from System import *;
from MySql.Data.MySqlClient import *;
 
connStr = (
	"Server=localhost;"
	"Database=test;"
	"User ID=myuserid;"
	"Password=mypassword;"
	"Pooling=false"
)
 
conn = MySqlConnection(connStr)
conn.Open()
cmd = conn.CreateCommand()
"""
requires a table to be created named employee
with columns firstname and lastname
such as,
   CREATE TABLE employee (
      firstname varchar(32),
      lastname varchar(32));
"""
sql = "SELECT firstname, lastname FROM employee"
cmd.CommandText = sql
reader = cmd.ExecuteReader()
while reader.Read():
	firstName = reader["firstname"]
	lastName = reader["lastname"]
	Console.WriteLine("Name: %s %s" % (firstName, lastName));
 
# clean up
reader.Close()
reader = None
cmd.Dispose()
cmd = None
conn.Close()
conn = None

And walla! You have to admit, that is pretty awesome! We've got the power of simplicity from Python along with the power of .NET at our finger tips!

You can also import libs that you've gac'd (installed via gacutil) by replacing line 2 with clr.AddReference("MySql.Data") which might be more useful in some cases.

Conclusion

There's so much we can do with this such as prototype, making simple test cases, or even utilities for your .NET application. I've found this lots of fun and hope you do too. Stay tuned and keep your eyes peeled for another article on roasting the same blend of code with Jython!

Be sure to also take a look at these other links that might interest you as well!

Share/Save/Bookmark

Firefox 3! Get it while it’s hot!

          0 votes
June 17th, 2008

Get it while its hot! ... or at least try :-P This morning when I woke up and started firefox I noticed it asking if I wanted to update to the latest version. Naturally I agreed but it failed to connect and download. I wonder if this is because a lot of people are trying to download or they were in the process of still updating the their links? I tried to update my browser from work as well and had the same issue but fear less you can download it just find from the site :-)

www.GetFirefox.com

New features include:

  • Noticeable Speed Improvments
  • Better Security
  • Enhanced Productivity
  • More Customization

... and more but you'll just have to download to see for yourself ;-)

Also for those of you not wanting to upgrade because your favorite plugins aren't compatible yet, well there is a solution... sorta... With the nightly tester plugin you can enable older Firefox plugins you have installed to work with your newer version of Firefox. There is no guarantee and you might experience some quirks since its meant only for development and testing purposes but I've enabled some older plugins for Firefox 2 and haven't noticed any problems but that doesn't mean you won't either. Just depends.

Anyways, Enjoy!

Share/Save/Bookmark

Party at the Playboy Mansion!

          0 votes
June 3rd, 2008

Watcha know about that!?!?

Me at Playboy Mansion party!

Sorry! Had to brag. I know developer conferences are just as fun ;-)

May 30th, 2008. Spike.com launch party at the Playboy Mansion!

Share/Save/Bookmark