31
May
08

Why jQuery Rocks

I wanted to see whats the deal behind in-place-editing with ajax (IPE). More specifically, I have a list of DOM elements with similar *class* and I want to enable IPE for all of them at once. First place I looked was Prototype, even though I’ve only used jQuery, and thats because I know Ruby on Rails uses a ‘component’ which does that automagically, and that uses Prototype.

Short story long, I ended up with 10 lines, 3 errors on the way, and 20 minutes deep, which included browsing for the source, copying the files, troubleshooting and reading Prototype documentation. Which isn’t bad at all.

Then, with the remaining 20 minutes I had dedicated for this little research I’ve decided to see what kind of stuff jQuery offers.

Enter jEditable

I can go along and say how great it is, how it does justice for jquery, and how it fits the mentality.

But i’ll just say this: it took me 1 line of code, 1 minute.

Goal

Hopefully you won’t waste time researching javascript frameworks for your next project. Just pick jQuery.

EDIT: I’ve cut this post 70% down.

24
May
08

Web MVC Frameworks

A while ago I’ve started playing with Ruby on Rails again. The last time I did that was pre-v1.0, so it really has been a while. Now days however, the MVC framework world is much different. The difference is that the first time I saw Rails, I (and most of the people back then) did not know very much of ORM, and there simply weren’t any such rapid framework around. So, with MVC.NET, django, pylons, and more around.. what has changed?

More importantly, now that we have the luxury of choosing, by what criteria can one examine alternatives.

I’m trying to compile a list, as I go over each of the frameworks, this is a work in progress so it is incomplete.

  • Model: how coupled is the framework and the ORM? how easy is it? what databases does it play with? (see: ActiveRecord)
  • View: which template engines are there? how coupled? whats the performance of rendering one? how clear is the syntax? (see: Haml, Breve for template beauty)
  • Helpers: what kind of syntactic sugar is there?
  • Forms: how easy is it to handle forms, read: are we able to load a model object from a POST directly, can we drop a model object to a form directly? can we generate an object from a request directly? can the framework generate the form in html for us?
  • Validation: what kind of validation is there? how capable is it? can we bind it to the model? to the form? how easy is it to add validation rules?
  • Authorization and Authentication: does the framework have a built-in module for that? how fast can we configure and run it? can we extend it?
  • Javascript/ajax: what libraries are supported? if none, how well will it play with one?
  • Scalability: apparently, no one knows about scalability, I will not pretend to know what its all about. But one can gather information about how scalable is a framework, for better or worse (worse, see: twitter )
  • TBC…
17
May
08

yielding

While reviewing xUnit’s sourcecode, I’ve stumbled upon this:

static IEnumerable<string> SplitLines(string input)
{
while (true)
{
int idx = input.IndexOf(Environment.NewLine);

if (idx < 0)
{
yield return input;
break;
}

yield return input.Substring(0, idx);
input = input.Substring(idx + Environment.NewLine.Length);
}
}

Thats a very nice use of yield. I’ve translated it to python just for fun:

Python

>>> def split(str):
while True:
idx = str.find(‘\n’);
if(idx < 0):
yield str
break

yield str[0:idx]
str = str[idx+1 :]

>>> g = split(“hello\nworld\nyea”)
>>> g.next()
‘hello’
>>> g.next()
‘world’
>>> g.next()
‘yea’

17
May
08

Asp ValidationSummary Alerts

If you want to use ASP.NET’s ValidationSummary, you have two options: display a div inline with the summary of the validation errors, or display an ugly alert() box.

There are a couple of guides which explain how to make ValidationSummary display the errors in a modal of your choice, but all are annoyingly incomplete. One even required you to change the ASP.NET core files, which is a hassle if you ask me.

I’m going to take a different, easier path.

Since ValidationSummary uses alert, I’ll replace alert with the modal of my choice.

function alert(msg) {   mymodal(msg); }

Now all you have to do is find a nice modal box.

11
May
08

Javascript Revelations #1

I’m starting to find out that javascript isn’t a crappy language at all. Did you know it’s closer to lisp than it is to Java?.

Heres currying in javascript.

>>> var c = function (b) { return function (a) { return b + a;}};
>>> var add5 = c(5)
>>> add5(3)
8
03
Feb
08

Update

Long time no blog. These are the things that happened lately.

  • School started after 3-month lecturer strike.
  • Completed MSC
  • Polished Hulz
  • Started a new project: Rub
  • Lost most of the sources for my fun/hobby coding in a HDD crash (As it happens, I do not backup those)
  • Started reading CLR via C#.
  • Started reviewing IronRuby sources.
  • Started reviewing Rotor (shared CLI) sources (oh boy).

I’ll post if I find anything interesting.

You could also check my new blog, in which I reserve the right to write (no pun intended)  in  Hebrew.

07
Jan
08

Next programming languages

What would my next new language endeavor be?.

  • F# – yes.
  • Erlang – went over it, couldn’t find anything suitable apart from the “chat server”. Syntax is a killer.
  • Eiffel maybe later.
  • CLOS maybe later.
  • Dylan maybe later
  • Ruby – refresh.
  • ANTLR– yes (not really a language).
05
Jan
08

HomeRow: Take Matters Into Your Hands

Home Row

Background

UPDATE: 01.02.2008 
Due to a hard-drive crash, I lost sources for HomeRow and other hobby projects of mine.  I’ve been requested to add configurable keys (was planned anyway). That will take time, since I’m reversing .Net IL into C# (but not too much time).
 
Usually experienced programmers navigate their code without using the mouse. This means, moving the right hand to arrows, and home/end/del keygroups. Alot of time can be lost by leaving the homerow in such a harsh way.
Someone already have defined it as a sort of VI mode for mode-less editing.

Getting it back!

HomeRow overloads your keyboard with additional functionality, using the CAPSLOCK key to toggle on/off. It isolates you from every IDE’s specific configuration, and gives you the same consistent interface without changing keyboards.
This is what your keyboards becomes only when CAPSLOCK is active.
hrlayout1.gif

Go wild…

You can now navigate your code using an FPS-like key layout (not really, FPSs use ASDW, this uses SDFE because its more natural)
Dont forget power-navigating, try CTRL-W which is now equivalent to CTRL-BKSP to delete whole words.
Try CTRL-F to jump to next word.
Play around!.

Download

This is free software, and no installation needed. It doesn’t do any permanent change to your layout of course.

Here is the Windows version.
Linux and OSX are in the works.

Notes and reqs

Reqs: .NET Framework 2.0, only tested on Windows XP.

Note: it does take time to get used to the fact that the keyboard is “overloaded”. You will notice yourself trying to move the caret and getting a stream of “ffffdddddwww”s, because you forgot to enable HomeRow. Once your mind adjusts, it [HomeRow toggling] becomes really fluent and addictive.
02
Jan
08

Eclipse PDE & log4j

In continuation of my quick and dirty tips for eclipse , if you’re developing an eclipse plugin, and want to use log4j in it, this is what you should do.

  1. Download log4j
  2. Extract log4j.jar to a directory in your plugin bundle layout. (e.g. /lib)
  3. Add an entry in MANIFEST.MF, Bundle-ClassPath: .. ,lib/log4j.jar ,..
  4. Create a log4j properties file somewhere in your plugin bundle layout. (/log4j/log4j.properties)
  5. public static final Logger log = Logger.getLogger(“com.mycompany”);
  6. PropertyConfigurator.configure(findFile(“/log4j/log4j.properties”));
  7. Anywhere in your code: log.info(“hello world”);

Heres how findFile works:

public static String findFile(String file)
{
String result=””;
try
{
result= FileLocator.toFileURL(FileLocator.find(getDefault().getBundle(), new Path(file), null)).getPath().toString();
}
catch(IOException ex)
{
ex.printStackTrace();
}
return result;
}

01
Jan
08

Programming Fonts

I’m rating my current favorites.

  1. Consolas 11pt (AA)
  2. Bitstream Vera (AA)
  3. Envy Code B 10pt
  4. Lucida Console
  5. Courier New 10pt*

*Not a programming font by definition but is lightweight and very familiar.

Programming fonts are featured to have a more condensed nature, so you could see more lines on your screen, better character disambiguation for common combinations: l1, o0, etc.

As a result I used to have Envy Code at the top, but after realizing it crams so much text it might strain my eyes in, lets say 3 years of prolonged usage, I went with Consolas and set it the highest size I could.

I admit I do sin and use Courier as the alternate font, since I’m not into anti-aliasing that much.  I am yet to find a replacement for Envy Code.

I’m also not sure yet if serifs are good for code readability.




May 2024
S M T W T F S
 1234
567891011
12131415161718
19202122232425
262728293031