Using .bind()

Use .bind damn it - Mike Puerto

I heard Mike rant about bind() a few months ago to all of us writing code on our app using RendrJS (by Airbnb). I had actually never thought of using it more often and i don’t really recall why. This is perhaps why one should be working with an awesome bunch of people around, one who kicks you in the rear to get things done the right way.

The bind() is actually pretty cool. What it does is basically create another function to which you can bind this. It’s pretty awesome when it comes to reusing as well.

Lets actually go with a very simple example using Breaking Bad reference.

Assume 1kg of Blue stuff is priced at a $1m.

So, lets write a very simple and a basic function to calculate the amount of Blue Stuff sold and the account balance with Walter White & Jesse Pinkman.

    function calculatBlueStuffAndAccountBalance (quantity) {
        this.blueStuff = this.blueStuff - quantity;
        this.accountBalance = this.accountBalance + quantity;
    }

Let us assume that all the money is in millions of $$ and blue stuff in Kgs.

Here is Walter White

    var walterWhite = {
        name: 'Walter White',
        blueStuff: 50,
        accountBalance: 10
    }

And our very own Jesse Pinkman

    var jessePinkman = {
        name: 'Jesse Pinkman',
        blueStuff: 100,
        accountBalance: 5
    }

So now, we can create a new function which can be reused with bind. Walter White can sell upto 2Kgs of Blue Stuff every month & Jesse Pinkman van sell upto, lets say, 3kgs.

    var walterWhiteMadeASale = calculatBlueStuffAndAccountBalance.bind(walterWhite, 2);

Now, just call the function each time to which is now binded to walterWhite

    walterWhiteMadeASale();

Same goes for Jesse Pinkman

    var jessePinkmanMadeASale = calculatBlueStuffAndAccountBalance.bind(jessePinkman, 3);
    
    jessePinkmanMadeASale();

Voila !

I use rendrJS as mentioned earlier and i use it in the callbacks when i save a model or a collection this way:

    this.model.save({}, {
        success: function (model, response) {
            this.app.flash('Successfully saved', 'success');
            // other stuff
        }.bind(this)
    })

Its much better than using var _this = this. Cleaner too.

Thanks Mike.

Dev tools i used big time in 2013

I am a web developer and i work remotely with an amazing team working from New York, India and Europe all the time. After having worked on Ruby on Rails for more than a year, i started writing Node.js this year.

Writing code all day long can be  exhausting but with the right tools, i think you can keep things going pretty easy.

1. Sublime Text

Definitely the best text-editor i have ever used. There are tons of options, packages with Sublime Text. (link)

image

2. Postman REST Client

Postman makes your life easy. If you are one of those guys who writes a lot of APIs then you should definitely try Postman. Only problem is that the interface is still not responsive. (link)

image

3. GistBox

I like Gist on Github but i like GistBox more. Better interface, Labels are just some of the features.(link)

image

4. Lightpaper

This year, we moved all of our documentation to GitHub private repos. Since then, i started using Markable to easily write markdown until i found Lightpaper for mac. There is nothing wrong with Markable but i just did not want another tab open on my browser.(link)

image

5. CodeKit

I have become a regular user of CodeKit. Gotta love the interface. (link)

image

6. Floobits

Remote Paired Programming with floobits is pure bliss. It took me some time to set it up but it was all worth it.(link)

Although, if you just want to share screens, then you should definitely try Screenhero and Glance too. I love Glance, its pretty light weight and works like a charm. I am still not the biggest fan of Screenhero though. Its pretty slow and heavy i feel.

image

7. Transmit

The go-to app for FTP.(link)

image

8. GitHub for mac

Sleek and nicely designed desktop client for GitHub. (link)

image

9. Appear.in

Free video conference with screen share and chat for upto 8 people without having to signup. Pure awesomeness.(link)

image

10. Html to Haml

htmltohaml.com helps to convert html markup to haml. Its that simple.

11. JS2Coffee

In my initial days of Coffeescript, i used JS2Coffee a lot. You can covert JS to Coffeescript and vice-versa. Really handy.

There are a few others that i have not mentioned here. i.e. JSLint, JSPerf, Codepen.io, Balsamiq, Mockup.io etc.

Immediately Invoked Functional Expression

Recently, at my work we’ve been interviewing a lot of candidates to fill the position of a Javascript developer. 30 and counting. One of the questions we ask candidates is if they have ever used IIFE ?

That exactly is the reason why i am writing this post. In Layman’s term, calling a function immediately after it’s declared is Immediately Invoked Functional Expressions a.k.a Immediate Functions

(function() {
    alert('Woot woot');
})();

The syntax looks a little scary, but don’t worry. The anonymous function has to be enclosed in parentheses. The second set of parentheses would invoke the function. If in case, you want to pass arguments to your IIFE then you can just pass them in these set of parentheses.

(function(name) {
    alert('Alerting ' + name);
})('Kaushik');

When to use ?

Using global variables is not really the best idea. So, if possible one should avoid it. The immediate functions could help you with that. Sometimes, you can get your work done without having to create extra global variables

function calculate(a, b) {
    var result = (function() {
        //.. some logic
        return result;
    })();
};

This is just a small example but i really hope you get the basic understanding of Immediate Functions

The MEAN Stack: MongoDB, ExpressJS, AngularJS and Node.js

mongodb:

By Valeri Karpov, Kernel Tools engineer at MongoDB and and co-founder of the Ascot Project

A few weeks ago, a friend of mine asked me for help with PostgreSQL. As someone who’s been blissfully SQL-­free for a year, I was quite curious to find out why he wasn’t just using MongoDB instead. It turns out that he thinks MongoDB is too difficult to use for a quick weekend hack, and this couldn’t be farther from the truth. I just finished my second 24 hour hackathon using Mongo and NodeJS (the FinTech Hackathon co­sponsored by 10gen) and can confidently say that there is no reason to use anything else for your next hackathon or REST API hack.

Read More

Why “1” is 1 and “2” is 2.

Found this on Quora recently

Lanyrd: from idea to exit - the story of our startup

ndowne:

I recently gave a talk at SmashingConf in Freiberg. I wanted to share the story of our startup Lanyrd and some lessons learned along the way. This article is based on that talk, the abstract of which is:

Natalie launched the first version of Lanyrd.com with her co-founder and husband Simon Willison, while on honeymoon in Casablanca. As the site took off, they realised their side project was destined to become something much bigger.

This talk will tell the story of Lanyrd from a two-week proof of concept to a fully-fledged startup, the lessons learned along the way about building and launching a product, running a company, raising investment and the entrepreneurship journey. This is the talk she wished she heard before getting started! In September 2013, just a week before the SmashingConf 2013, Lanyrd was acquired by Eventbrite.

image

Our startup story begins in June of 2010 with our wedding - a rather unconventional beginning to be sure.

image

(Photo: http://www.flickr.com/photos/chuckp/21394313 )

Simon and I met in the first week university, 10 years before we got married. In our time together we had already built and launched several side projects.

After the wedding, we quit our jobs, gave up our flat in Brighton and set out on honeymoon overland through Europe and northern Africa. Our intention was to travel as long as we could, whilst earning money from freelance projects on the way.

When we got to Casablanca in Morocco we fell ill with food poisoning.

image

It was Ramadan so we couldn’t buy food during the day, and we were too ill to continue travelling so we hired a flat and hacked on a prototype of Lanyrd, an idea I’d had that we had been discussing over a few preceding weeks.

We built something that we wanted to exist. A week later, when we launched the first possible version that worked to our friends in private alpha, we realised it was something other people needed too.

Lanyrd is a social conference directory: we help people and companies find the best conferences and professional events to go to, help them get the most out of them whilst they are there and provide a space to collate slides and videos after the event.

Read More

#Roadtrip #Countryside #Drive #RoadMojo #Greenery #Roads