Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View sgreenfield's full-sized avatar

Scott Greenfield sgreenfield

  • Omaha, NE
View GitHub Profile
@sgreenfield
sgreenfield / gist:9258154
Created February 27, 2014 19:56
Coinbase Average Price Calculator Bookmarklet
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)()
@sgreenfield
sgreenfield / gist:9258036
Last active November 3, 2015 04:17
Coinbase Average Price Calculator
// 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 });
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)
@sgreenfield
sgreenfield / sugar-date-vs-native-vs-tzdate.js
Created April 30, 2013 20:03
Sugar.js v.s. native Date v.s. tzDate - Performance tests
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');
@sgreenfield
sgreenfield / keylogger.js
Created April 24, 2013 21:25
monitors keypress events and fires different event depending on whether or not the keypress actually produces a character with a value
;(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 );
});
});
//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); }
//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: [
@sgreenfield
sgreenfield / gist:4043009
Created November 9, 2012 00:49
Geordi La Forge dialog generator
//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(),
@sgreenfield
sgreenfield / gist:2871423
Created June 4, 2012 23:18
jQuery keypress with intent to type a value
$(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);
}
});
@sgreenfield
sgreenfield / gist:2802070
Created May 27, 2012 03:35
JavaScript updateQueryStringParameter
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;
}