This file contains 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
String.prototype.repeat = function(times) { | |
return new Array(isNaN(times) ? 1 : ++times).join(this); | |
} |
This file contains 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 zero_pad = function(value, length) { | |
value = value.toString(); | |
while (value.length < length) | |
value = '0' + value; | |
return value; | |
}; |
This file contains 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 Timespan = function(milliseconds) { | |
this.milliseconds = milliseconds; | |
this.seconds = this.milliseconds / 1000; | |
this.minutes = this.seconds / 60; | |
this.hours = this.minutes / 60; | |
this.days = this.hours / 24; | |
this.weeks = this.days / 7; | |
this.months = this.days / 30; | |
this.years = this.months / 12; | |
this.centuries = this.years / 100; |
This file contains 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
String.prototype.replaceAt = function(index, char) { | |
return this.substr(0, index) + char + this.substr(index + char.length); | |
} |
This file contains 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
Array.prototype.intersect = function(b) { | |
return this.filter(function(n) { | |
return (b.indexOf(n) != -1); | |
}); | |
} | |
Array.prototype.diff = function(a) { | |
return this.filter(function(n) { | |
return !(a.indexOf(n) > -1); | |
}); |
This file contains 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 sys = require('sys'), | |
events = require('events'); | |
var Emission = module.exports = function () { | |
events.EventEmitter.call(this); | |
this.cycles = 0; | |
}; | |
sys.inherits(Emission, events.EventEmitter); |
This file contains 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 sys = require('sys'), | |
Emission = require('./emission'); | |
var emission = new Emission(); | |
emission.cycle(); | |
emission.on('recycle', function(cycles) { | |
if (cycles < 10) { | |
sys.puts(cycles); | |
} |
This file contains 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
Browse: | |
https://oauth.twitter.com/2/authorize?oauth_callback_url=http://www.skyrock.com/&oauth_mode=flow_web_client&oauth_client_identifier=7ynojZQ3uVE2DifWftbS3w | |
After authentication, user gets redirected to: | |
http://www.skyrock.com/#oauth_access_token=RnEJAQAAAABpYH8NAAAAAGKSBQAAAAAAr9G2hLrnXaznri8LlSIaR0HuNBI=HLx1r47oqpobPncAm9DNeRCdySaMqoTKJcCLwnhIP&oauth_bridge_code=2wxWDd3IIZ0UW1y4oFpioWfbzTeaAlSGoJk5L6qMpGQ | |
...Use the API: |
This file contains 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
_.mixin({ | |
missing: function(obj, requirements) { | |
var missing = {}; | |
_.each(requirements, function(requirement, field) { | |
if (_.isNull(obj[field]) || _.isUndefined(obj[field])) { | |
missing[field] = false; | |
return; | |
} | |
if (typeof obj[field] === 'object') { | |
potential = _.missing(obj[field], requirement); |
This file contains 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
#!/usr/bin/env coffee | |
guid = (length = 32) -> | |
chars = '0123456789abcdef' | |
result = '' | |
while length-- | |
result += chars[Math.floor(Math.random() * chars.length)] | |
return result |