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
javascript:(function()%7Bvar%20%24rows%3D%24('%23transfers_list%20tr%3Agt(0)')%2Corders%3D%5B%5D%2CtotalQuantity%3D0%2CtotalPrice%3D0%3B%24rows.each(function()%7Bvar%20a%3D%24.trim(%24(this).find('td%3Aeq(5)').text()).split('%20')%5B0%5D*1%2Cquantity%3D%24.trim(%24(this).find('td%3Aeq(3)').text()).split('%20')%5B0%5D*1%3Borders.push(%7Bquantity%3Aquantity%2Crate%3Aa%7D)%7D)%3B%24.each(orders%2Cfunction(i%2Ca)%7Bvar%20b%3Da.rate*a.quantity%3BtotalQuantity%2B%3Da.quantity%3BtotalPrice%2B%3Db%7D)%3Balert('paid%20average%20of%3A%20'%2B(totalPrice%2FtotalQuantity)%2B'%20for%20'%2BtotalQuantity)%7D)() |
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
// Go to the URL below and execute this JavaScript to calculate your coinbase average Bitcoin purchase price and the total purchased. | |
// https://coinbase.com/transfers | |
// Bookmarklet can be found here: https://gist.github.com/sgreenfield/9258154 | |
var $rows = $('#transfers_list tr:gt(0)'), orders = [], totalQuantity = 0, totalPrice = 0; | |
$rows.each(function(){ | |
var rate = $.trim( $(this).find('td:eq(5)').text() ).split(' ')[0] * 1, | |
quantity = $.trim( $(this).find('td:eq(3)').text() ).split(' ')[0] * 1; | |
orders.push({ quantity: quantity, rate: rate }); |
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
Date.prototype.toRelativeTime = function(date) { | |
var delta = date - this, units, conversions; | |
conversions = { | |
millisecond: 1, // ms -> ms | |
second: 1000, // ms -> sec | |
minute: 60, // sec -> min | |
hour: 60, // min -> hour | |
day: 24, // hour -> day | |
month: 30, // day -> month (roughly) |
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
console.clear(); | |
var amountOfTests = 5000, | |
newDate, tzDateMake, dateCreate, tzDateCreate; | |
console.time('new Date'); | |
amountOfTests.times(function(){ | |
newDate = new Date("2010-12-26T06:00:00Z"); | |
}); | |
console.timeEnd('new Date'); |
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
;(function($){ | |
//monitors keypress events and fires different event depending on whether or not the keypress actually produces a character with a value | |
$.fn.keylogger = function() { | |
return this.each(function() { | |
$(this).keypress(function(e) { | |
if ( hasValue(e) ) $(this).trigger( 'keylogger:withvalue', [String.fromCharCode(e.charCode), e] ); | |
else $(this).trigger( 'keylogger:novalue', e ); | |
}); | |
}); |
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
//micro backbone-ish experiment with prototypal inheritance | |
var Vertebra = {}; //not backbone.js, not spine.js, Vertebra! | |
Vertebra.instance = function(){ | |
this.initialize(arguments); | |
}; | |
Vertebra.create = (function() { | |
function F(args){ return Vertebra.instance.apply(this, args); } |
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
//meta validation | |
//idea for dynamic validation to enable model validation to change its own validation on the fly | |
//example syntax below | |
var validation = { | |
rules: [ //model attribute rules | |
'recipient_type': { | |
//on: true, //always on by default | |
when: [ |
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
//requires sugar.js (because I spent like 30 seconds on it) | |
//dialog source: http://stuff.mit.edu/afs/athena/activity/h/humor/Incoming/laforge.dialogue.generator | |
descriptor = 'electro-magnetic disruptive destructive'.words(); | |
verbs = 'reconfigure assemble bypass amplify re-route polarize'.words(); | |
nouns = 'field transducer coil dispersion phase-disruptor anus resonance sub-space tachyon induction pulse matrix baryon conduit wave-guide lepton discriminator polarization electro-magnetic frequency bandwidth antimatter diagnostic mode plasma spectral emitter'.words(); | |
enemies = 'klingons romulans herpes'.words(); | |
var laforge = "Captain, we're going to have to {verb1} the {descriptor1} {nouns1}, and {verb2} the {descriptor2} {nouns2} in order to prevent the {enemy} from penetrating our shields".assign({ | |
verb1: verbs.sample(), |
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
$(document).keypress(function(e) { | |
var code = (e.keyCode) ? e.keyCode : e.which, character; | |
if(e.charCode && code !== 32 && code !== 13 && !e.altKey && !e.ctrlKey && !e.metaKey){ | |
character = String.fromCharCode(e.charCode); | |
console.log('value: ', character); | |
} | |
}); |
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
function updateQueryStringParameter(a, k, v) { | |
var re = new RegExp("([?|&])" + k + "=.*?(&|$)", "i"), | |
separator = a.indexOf('?') !== -1 ? "&" : "?"; | |
if (a.match(re)) return a.replace(re, '$1' + k + "=" + v + '$2'); | |
else return a + separator + k + "=" + v; | |
} |
NewerOlder