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 / 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;
}
@jlong
jlong / uri.js
Created April 20, 2012 13:29
URI Parsing with Javascript
var parser = document.createElement('a');
parser.href = "http://example.com:3000/pathname/?search=test#hash";
parser.protocol; // => "http:"
parser.hostname; // => "example.com"
parser.port; // => "3000"
parser.pathname; // => "/pathname/"
parser.search; // => "?search=test"
parser.hash; // => "#hash"
parser.host; // => "example.com:3000"
@sgreenfield
sgreenfield / gist:2362751
Created April 11, 2012 21:24
ASCII Looks of Disapproval
ಠ_ಠ
ಠ~ಠ
ಠoಠ
ಠxಠ
ಠ.ಠ
@wilsonpage
wilsonpage / router.js
Created November 26, 2011 12:32
Example router module
define([
'jQuery',
'Underscore',
'Backbone',
'modules/feed',
'modules/files',
'modules/members',
'modules/misc/GBL',
'modules/misc/lightbox'
], function($, _, Backbone, Feed, Files, Members, GBL, Lightbox){
class CustomFailure < Devise::FailureApp
# Never do http authentication through Devise
def http_auth?
false
end
def redirect_url
send(:"new_#{scope}_session_path", :format => (request.xhr? ? 'js' : nil ))
end
@jackfuchs
jackfuchs / jquery.support.cssproperty.js
Last active July 19, 2024 17:38
Extends the jQuery.support object to CSS Properties
/**
* jQuery.support.cssProperty
* To verify that a CSS property is supported
* (or any of its browser-specific implementations)
*
* @param p css property name
* @param rp optional, if set to true, the css property name will be returned
* instead of a boolean support indicator
* @return {mixed}
*