Blog
jQuery plugin to fetch tweets using the Twitter JSON API
Posted by Lupo Montero on
Over a year ago I posted a script showing how you could fetch tweets using jQuery and Twitter's JSON API, and to my surprise it has had a decent amount of traffic. So now that I've been learning more JavaScript and jQuery I decided to re-write the script as a jQuery plugin.
The plugin allows for much easier re-use and integration as well as adding some features like optionally showing the users profile data and autorefresh.
Once jQuery and the plugin are loaded you can load a user's tweets as simple as:
$('#some-element').fetchTweets({ username: 'some-twitter-user' });
Hope you enjoy!
Building a town/country picker using Google's Geocoding API and jQuery
Posted by Lupo Montero on
I'm currently working on a new "social" site for a startup and when building some of the forms, one of the bits of information we need to collect from users is their country and town or city. Nothing really new, but I didn't want to build an enormous dropdown with every country in the world and then leave the city/town bit as a simple text input. In this case the possibility of building a city/town dropdown based on the choice of country just seems nonsense.
So I then remembered how Facebook does it. They give you a simple input field and as you start typing it will show a list with options of places matching the string you've typed so far. You then select the desired location from the list and voila. Neat.
Installing PHP's OAuth PECL extension on Mac OS X Snow Leopard
Posted by Lupo Montero on
I recently reinstalled the operating system on my Macbook and this time around I decided to use homebrew to manage packages. Since php comes pre-installed with OS X and homebrew encourages using the pre-installed binaries, I have been using the built-in install of php, and so far so good.
But today I tried to install php's OAuth extension, which comes as a pecl package, and I run into some errors
Writing Node.js modules in C++
Posted by Lupo Montero on
Today I found myself looking at how to write node.js modules in C++. I read @izs's article on the How to Node website and felt tempted to explore the C++ route, being already familiar with their JavaScript counterparts.
I am no C++ expert, in fact I'm quite a noobie, but I have read a lot of it (it is used to ilustrate programming concepts in sooooo many books) and even managed to write a couple of command line tools for my own use. Anyway, the idea of this post is to show the most basic interaction between a C++ module and node.js. The examples I have seen have been very useful, but I felt the need to simplify the code even more and reduce the "hello world" module into the bare minimum.
Using JavaScript closures to create private scopes
Posted by Lupo Montero on
One of the best known problems in JavaScript is it's dependance on a global scope, which basically means that any variables you declare outside of a function live in the same name space: the ominous window object. Because of the nature of web pages, many scripts from differnt sources can (and will) run on the same page sharing a common global scope and this can be a really really bad thing as it can lead to name collisions (variables with the same names being overwritten) and security issues.
To minimise the problem we can use JavaScript's powerful closures to create private scopes where we can be sure our variables are invisible to other scripts on the page.
So what is a closure? Well, I could have used the definition given by Wikipedia, but after reading it myself I think we need a simpler, more practical explanation for web developers.