Skip to content

Instantly share code, notes, and snippets.

@karlwestin
karlwestin / gist:2690501
Created May 13, 2012 22:24
Refactoring JS for testing part 5 – refactor
/*
* Karl Westin
* Part of the "refactoring javascript for unit testing" blog post
*/
function Lightbox(boxcontent, $parent) {
this._addElements(boxcontent, $parent);
this._autoSize();
this._bindEvents();
}
@karlwestin
karlwestin / gist:2703327
Created May 15, 2012 17:06
Server response
// Thoughts about server response for payment/minimum plan
// server calls something like
/api/accounts/:id // id for example 34667
//getting all the data
/api/accounts/all
//The exact URL structure is not so important, just whether we can use id's and "all", or if we need smth else :)
@karlwestin
karlwestin / gist:2712382
Created May 16, 2012 17:25
filtering out highlights
minimum_plan: {
metadata: { .... },
graph: [ [21312412, 123], [1231212312, 1123], [1231231, 1231231, { text: "Finished account x" ... }] ]
}
var highlights = _.select(minimum_plan, function(el) { return !!el[2] });
@karlwestin
karlwestin / gist:2717190
Created May 17, 2012 07:31
Questions for Scott Jehl about working/travelling:
Hi Scott!
Well, i have a ton of questions, i realize you can't answer all straight away but maybe some can be discussed in the post :)
• How much have you been able to work/week approximately?
Like, what's realistic while still enjoying the trip?
• Did you split things up between "work weeks" and "travel weeks" or what methods have you tried?
• Am I asking pointless questions about separating work/travel and looking for the wrong type of answer? :P
$.post("/api/web2/authed/bonus-slider", { accountId: 2 }, function(e) { console.log(e) });
@karlwestin
karlwestin / gist:3163157
Created July 23, 2012 11:24
throttling a window.scroll handler for better performance
// underscore's throttle-metod
var throttle = function(func, wait) {
var context, args, timeout, throttling, more, result;
var whenDone = _.debounce(function(){ more = throttling = false; }, wait);
return function() {
context = this; args = arguments;
var later = function() {
timeout = null;
if (more) func.apply(context, args);
@karlwestin
karlwestin / gist:3165015
Created July 23, 2012 17:57
One example of BB View method to save user data, while re-using the validation mechanism from the model
// this one doesn't throw away any data the user entered, it even keeps the invalid stuff:
onError: function(errors) {
var data = this.prepare(),
triedData = this.getData();
_.extend(data, triedData);
data.errors = errors;
this.$el.html(this.template(data));
@karlwestin
karlwestin / gist:3175457
Created July 25, 2012 10:26
DEKANYIFY twitter
/*
Are you also tired of people writing in caps for stupid reasons on twitter?
My farvorite example is @zerohedge: "FITCH DEGRADES CAMERONS CAT TO BB" and shit like that.
Fuck it.
Anyway, right click the bookmarks-bar. Find a good name for it. paste the following:
*/
javascript:$(".js-tweet-text").each(function(index, el) { var $el = $(el), content = $el.html().toLowerCase(); $el.html(content) })
@karlwestin
karlwestin / README.md
Created August 10, 2012 10:01 — forked from iloveitaly/README.md
My Github Issues

First install the required gems:

gem install octokit awesomeprint rainbow

Then run it to extract all of your open GitHub issues into files (with comments).

ruby my-gh-issues.rb
@karlwestin
karlwestin / gist:3480824
Created August 26, 2012 15:01
Backbone.js: 'change' events triggers though nothing changed since last 'change' event
/*
Line 775, tests/model.js
https://github.com/documentcloud/backbone/commit/69b80f5e3a86452c4150caa249332f9ea4efd901#L1R737
*/
test("multiple nested changes with silent", 2, function() {
var changes = [];
var model = new Backbone.Model();
model.on('change:b', function(model, val) { changes.push(val); });
model.on('change', function() {