This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// If you really need to do pagination clientside (ie. you have | |
// everything you want to paginate already in the page), then | |
// with a little jQuery and Underscore it needn't be a big deal. | |
// Assuming you have a couple of ULs with a bunch of LIs in them | |
// that you wish to paginate over, let's say one called `users` | |
// and one called `orders`, then this will do the trick: | |
(function paginate() { | |
_.each($("ul.users, ul.orders"), function(ul) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Put this in a utility file somewhere. (Requires Underscore.) | |
var Eventable = { | |
on : function(event, callback) { | |
this.events[event] = callback; | |
return this; | |
}, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* This will give you something to start with, anyway */ | |
.slider-container { | |
position : relative; | |
} | |
.track, .thumb { | |
position : absolute; | |
top : 0; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Depends on Underscore, nothing else. | |
// You could easily extend this to have proper hands, markers, numbers, etc. | |
var Clock = function(_params) { | |
var Utils = { | |
Maths : { | |
degreesToRadians : function(degrees) { | |
return degrees * Math.PI / 180; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// We had a use-case where we wanted to apply some styles at a certain | |
// breakpoint *and* to any IEs less than 9 (using the standard .lt-ie9 | |
// class). | |
// | |
// The developer tasked with this decided Sass couldn't do it, | |
// wrote a snarky comment, and then copied and pasted the code twice, | |
// sort of like this: | |
@media only screen and (max-width: 500px) { | |
a { ... } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// If you've ever written code like this: | |
var result; | |
_.each(somethings, function(something) { | |
if (something === particularSomething) { | |
result = something; | |
} | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This probably isn't a good thing to want to do, but it came up for me, | |
# so in the spirit of helping others with weird problems (and because this | |
# seems to be documented almost nowhere): | |
after_save do | |
if some_failing_condition | |
errors.add(:something, "some failure happened.") | |
raise ActiveRecord::RecordInvalid.new(self) | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Foo < ActiveRecord::Base | |
scope :random_n, -> (n) { limit(n).order("RANDOM()") } | |
end | |
Foo.random_n(5) # -> five randomly chosen Foos | |
# For extra points, put this sort of thing into a Concern. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Sometimes you care about the order in which RequireJS-loaded modules | |
// are retrieved, and wish to execute a callback for each module in the | |
// order in which you originally specified them, rather than the order | |
// in which they are loaded. You can do this with a queue. | |
var Queue = function() { | |
var q, | |
callCount = 0; | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var webdriver = require("selenium-webdriver"); | |
var driver = new webdriver.Builder(). | |
usingServer("http://localhost:4444/wd/hub"). | |
withCapabilities(webdriver.Capabilities.phantomjs()). | |
build(); | |
describe("Get the title of the Google homepage", function() { | |
it("should be 'Google'", function(done) { |