Looks like the number of frameworks/libs/tools available for “realtime” web apps is growing. I’ve been following them since socket.io appeared for the first time. Below is the list of tools I ran into in the past. I will try to keep this list up to date.
Jasmine is a behavior-driven development framework for testing JavaScript from Pivotal Labs (I believe Rajan Agaskar was/is the original author). I’ve been using Jasmine for a while now to test my JavaScript code. Today I ran into interesting situation where I wanted to test events bound to jQuery element. Basically by writing code like this:
$('#el').bind('click',function(e){ // handler code goes here });
I wanted to know if element $(‘#el’) had any events attached to it. I looked around but couldn’t find any predefined matchers in jasmine or jasmine-jquery to accomplish it. I realized that it’s pretty easy to extend jasmine and define my own matchers (which is pretty cool).
Here is how you can do it:
First define your new matchers:
var eventMatchers ={
toHaveEvent:function(event){ var data = jQuery.data(this.actual.get(0)); for(obj in data){ if(data.hasOwnProperty(obj)){ for(eventName in data[obj].events){ if(data[obj].events.hasOwnProperty(eventName)){ if(event === eventName){ returntrue; } } } } } returnfalse; } };
Then in your spec add your handlers inside beforeEach:
Often I have to login to different machines. It’s annoying to always type the full hostname and then password. So here is what you can do to avoid typing too much:
1. On your local machine create a private and public key:
ssh-keygen-t rsa
by default 2 keys will be created (id_rsa, id_rsa.pub) under ~/.ssh
2. Create config file under ~/.ssh
touch ~/.ssh/config
3. Add your connection information to config file:
Host HOST_ALIAS # can be anything you want
Hostname HOST_NAME # example.com
User USERNAME
port PORT
4. Create .ssh folder on the remote machine from your local machine (you will be prompted for the password):
ssh HOST_ALIAS mkdir-p .ssh
5. Finally append your new public key id_rsa.pub to ~/.ssh/authorized_keys on your remote machine (you will be prompted for the password one last time):
Tonight I found a plugin to auto escape html in order to protect from XSS attacks. I’m not sure why rails doesn’t do it out of the box (you have to use h() helper). Anyway the plugin is called xss_terminate and it can be found here. The cool thing about it is that now you can forget about h() .