Archive of articles classified as' "Uncategorized"

Back home

inspiring things

14/01/2012

Here is the list of talks, presentations, movies which inspired me in some ways:

1. Steve Jobs’ 2005 Stanford Commencement Address

2. David Heinemeier Hansson at Startup School 08

3. Web 2.0 Expo NY: Gary Vaynerchuk

4. The Holstee Manifesto: Lifecycle Video

Please let me know if you run into any interesting talks I will keep adding them here.

No Comments

Node.js libs for realtime web apps

26/09/2011

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.

  1. socket.io
  2. nowjs
  3. faye
  4. juggernaut
No Comments

Extending Jasmine Matchers

3/07/2011

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) {
              return true;
            }
          }
        }
      }
    }
    return false;
  }
};

Then in your spec add your handlers inside beforeEach:

describe("Element", function () {
  beforeEach(function () {
    this.addMatchers(eventMatchers);
  });
});

That’s it! Now you can use your new matchers inside your spec. In this case I was able to use it like this:

describe("Element", function () {
  beforeEach(function () {
    this.addMatchers(eventMatchers);
  });
 
  describe("when event attached", function () {
    it("should contain attached event", function () {
      setFixtures('<div id="el"></div>');
      $('#el').bind('click', function () {});
      expect($('#el')).toHaveEvent('click');
    });
  });
});
No Comments

ssh without a hostname and password

15/06/2011

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):

cat ~/.ssh/id_rsa.pub | ssh HOST_ALIAS 'cat >> .ssh/authorized_keys'

That’s all! Now every time you want to login to your remote machine you can type:

ssh HOST_ALIAS

and you should be able to get in.

No Comments

Academia vs. Business

18/11/2009

Academia vs. Business

No Comments

Gemcutter & Jeweler

17/10/2009

More about gemcutter & jeweler can be found here.

Here are the steps how to publish patched gem cloned from github:

1. Append username to gem name in .gemspec or if you use jeweler open Rakefile and edit Jeweler::Tasks section save it and run:

rake gemspec

2. Build gem with:

gem build

3. Push new gem to gemcutter

gem push
No Comments

BDD with Cucumber by Ben Mabey

29/08/2009

No Comments

auto escaping html in Rails to protect from XSS

29/07/2009

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() :) .

1 Comment

Cron in Ruby

27/07/2009

Check out how Whenever gem can simplify cron configuration.

No Comments

key-value store

26/07/2009

Key/Value DB

No Comments