isInt() JavaScript function

May 22, 2006
23 comments Web development

Here's my take on a function that determines if a variable is an integer or not before or after it's been recast to an int. The functionality is very similar to Python's 'isdigit()' function which works like this:


>>> assert "1".isdigit()
>>> assert not "1.0".isdigit()

However, my Javascript function should return true when the input is an integer or a string of an integer. Here it goes:


function isInt(x) {
   var y = parseInt(x, 10);
   return !isNaN(y) && x == y && x.toString() == y.toString();
}
assert(isInt("1"));
assert(isInt(1));
assert(!isInt("1a"));
assert(!isInt("1.0"));

You can see it in action here.
To be honest, I'm writing about this here just to not forget it the next time I need a similar function. Sorry to cause any interweb-noise.

UPDATE

Corrected whitespacing and made a jsFiddle link.

SVN + ./todo + crontab

May 20, 2006
1 comment Linux

I've now started playing with ./todo which is a really promising method (for me) for maintaining a simple todolist. When at work I more or less live on the command line and can do things there much faster than I can with an online todolist or a proper GUI. Now I simply write:


$ todo add Call Jan about svn repo

and it adds "Call Jan about svn repo" to my todo list. To view the todo list I simply write:


$ todo list

Every item in the list has a number which you can use to mark things done or change priority.

Anywho, now I've put my little todo.txt in my personal SVN repository on one of our servers. But, how do I make sure that my changes to the todo list are always backed up with SVN (subversion)? I could hack the ./todo script to do a svn commit on every change and svn update every time I do a ./todo list but that would be far too slow.

Truncated! Read the rest by clicking the link below.

Pixoh.com and Instant Domain Search

May 16, 2006
0 comments Misc. links

If you haven't already looked at Pixoh.com you've missed a great site. Pixoh's strapline is "Edit pictures online" and that's what it does. And well. Sure, it's no Photoshop or Gimp but it's good enough for most of the image operations you might want to do. I've recommended lots of people to edit their images there if they don't have an image editing program installed.

What's nice about Pixoh.com is that it's written in Twisted AND looks great. Few people are smart enough to grasp this powerful Python framework AND have the artistic talent too. It's not uncommon that clever brainiacs have ugly looking websites with horrible colours written in Lisp or Haskell and artistic people have beautiful websites written in PHP. Look at the Zope 3 website compared to CakePHP. I know, before you flame me, I'm generalising and exaggerating but you must admit that there's a pattern out there isn't it?

When I had a look at Pixoh.com I also discovered their other project called Instant Domain Search which is brilliant for finding out what .com, .net and .org domains are taken or not. Sadly, there's very little left to register. With instant domain search you can start typing and for every letter you enter it (almost) immediately says if the current word is registered or not.

Check these out. I've bookmarked both of them!

Watford kung fu club

May 4, 2006
2 comments Kung Fu

Pen Rance, who wrote the book Martial Arts that I mentioned about a month ago has now set up a kung fu club in Hertfordshire. It's called FWC Herts

If you live in the Herfordshire Watford area, I genuinely recommend that you give it a try if you want to get fit or you're already fit but bored with the local gym.

UPDATE

This club is now run by instructor Carlo Fernandes

Mobile-review.com

May 2, 2006
3 comments Misc. links

Mobile-review.com In the process of buying a new mobile phone? And possibly extra curious on the phone's camera capabilities? Then check out Mobile-review.com I just discovered it today. It's got really lengthy, detailed and comparative reviews not only in specs but with plenty of pictures and the authors "personal impressions" too.

Sadly no review of my phone, the Treo 650 but from this page I count about 75 reviews just of various Nokia phones.

Nice websites like this are hard to find. Keep up the good work [Russian] guys!

Private functions in Javascript?

April 29, 2006
3 comments Web development, Python

In Python you indicate whether a function/method is private by naming it so that it starts with an _ underscore like this:


def _thisIsPrivate():
    return 'a'

def thisIsPublic():
    return 'b'

It means that if you have these two functions in a file called dummy.py and you do something like this:


>>> from dummy import *
>>> thisIsPublic()
'a'
>>> _thisIsPrivate()
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
NameError: name '_thisIsPrivate' is not defined

Seems fair doesn't it. Now is there such similar naming convention and functionality in Javascript?

Truncated! Read the rest by clicking the link below.

type - Writing shell scripts

April 28, 2006
1 comment Linux

I've started skimming through the lovely Writing shell scripts tutorial and even though I'm just in the beginning of it I've already learnt one very useful thing: the type program. With it you can find out "what type of command it is". This is useful because sometimes you want to know where some command is coming from. I'll let this example explain its usage:


peterbe@trillian:~ $ type jed
jed is /usr/bin/jed
peterbe@trillian:~ $ type cvs_commit 
cvs_commit is /home/peterbe/bin/cvs_commit
peterbe@trillian:~ $ type alias
alias is a shell builtin
peterbe@trillian:~ $ type sjed
sjed is aliased to `sudo jed'

I'll read more of this after the weekend.

Helpdeskshow - a quick review

April 26, 2006
0 comments IssueTrackerProduct

I just got back from the Helpdesk & IT Support Show in Olympia (Kensington, London). My main impression is: there are many, big players in this industry.

My pet project, the IssueTrackerProduct is very basic in comparison to some of these companies products. Although it's often used in help desk situations the kind of help desk solutions I've seen today are way different. For many of them, it's all about integrating various systems such as asset management, call logging, configuration management, knowledge management, etc. It seems that the actual help desk apps seems to have to be low priority compared to getting all pieces to fit together.

Truncated! Read the rest by clicking the link below.

Interesting float/int casting in Python

April 25, 2006
21 comments Python

Casting is when you convert a variable value from one type to another. This is, in Python, done with functions such as int() or float() or str(). A very common pattern is that you convert a number, currently as a string into a proper number.

Let me exemplify:


>>> x = '100'
>>> y = '-90'
>>> print x + y
100-90
>>> print int(x) + int(y)
10

That was the int() function. There's also another very common one which is float() which does basically the same thing:


>>> print float(x) + float(y)
10.0

Truncated! Read the rest by clicking the link below.

Best bicycle locks

April 22, 2006
1 comment Misc. links

The Kryptonite NYFU This is a great article about the best bicycle locks that this guy can find. He buys a bunch of different cable locks, U-locks and chains. (Sometime U-locks are called D-locks but I think it's the same thing)

He then pursues to lock up his bike and then tries to break the lock with a set of different hand tools such as hacksaw, bolt cutters, crowbar etc. Every lock is judged by security, ease of use and value in price but security is a 20 point scale whereas ease of use and value is a 10 point scale.

I like this article because A) I can learn something about what lock to buy for my bike and B) it's nice to see when someone puts his efforts in to put together a nice little article like this.

Thank you Scott Elder for the review!