Skip to content

Instantly share code, notes, and snippets.

View jakeboxer's full-sized avatar

Jake Card jakeboxer

View GitHub Profile
# Prevent double-clicking on things, with fix for button value
$(document).on 'click', '[data-disable-with]', ->
$element = $(this)
this.disabled = true
if disableWith = $element.attr('data-disable-with')
$element.html(disableWith)
# This is a hilarious and gross fix to get the clicked button's name and
hash = {:dog => 'woof', :cat => 'meow'}
without_dup = hash
with_dup = hash.dup
# BEFORE CHANGE
puts "hash: #{hash.inspect}"
puts "without_dup: #{without_dup.inspect}"
puts "with_dup: #{with_dup.inspect}"
# sinatra
get "/:arg" do
render my_database.send arg
end
def refactored_call_on_upcased_string(str, method_name)
str.upcase.send(method_name)
end
def call_on_upcased_string(str, method_name)
# Save this file as hey.rb
#
# $ ruby hey.rb
# HEY GURL
puts DATA.read.upcase
__END__
hey gurl
@jakeboxer
jakeboxer / gist:6274618
Last active December 21, 2015 07:58
From the bankofamerica.com front page
<script type="text/javascript">
if (self == top) {
var theBody = document.getElementsByTagName('body')[0];
theBody.style.display = "block";
}
else {top.location = self.location;}
</script>
# Prevent double-clicking on things
$(document).on 'click', '.js-disable-on-click', ->
$element = $(this)
$element.attr('disabled', 'disabled')
$element.html($element.data('disabled-text'))
# Disabling the button prevents the form from submitting, so we have to force
# the submit here.
$element.closest('form').submit()
@jakeboxer
jakeboxer / loljavascript.js
Last active March 29, 2016 12:40
lol javascript
var dateValue = 504001800000; // Saturday, December 21st, 1985 at 3:30am EST
var date1 = new Date(dateValue);
var date2 = new Date(dateValue);
console.log(date1 == date2); // false (different instances)
console.log(date1 === date2); // false (different instances)
console.log(date1 > date2); // false (date1 is not later than date2)
console.log(date1 < date2); // false (date1 is not earlier than date2)
console.log(date1 >= date2); // true (rofl)
console.log(date1 <= date2); // true (ahahahaha)
@jakeboxer
jakeboxer / gist:5803136
Created June 18, 2013 06:44
Memoizing methods with options
class Eminem
def spaghetti(options={})
@spaghetti ||= {}
@spaghetti[options] ||= Spaghetti.new(options)
end
end
e = Eminem.new
e.spaghetti # Calculates
centerMobileBanner = ->
$mobileBannerText = $('.mobile-banner span')
$mobileBannerText.css('left', ($(window).width() * 0.5) - $mobileBannerText.width() * 0.5)
$(document).ready(centerMobileBanner)
$(window).resize(centerMobileBanner)
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
widgetPath: 'public/static/components',
relativeCoffeePath: '**/javascripts/**',
coffee: {
compile: {
files: [
{
expand: true,
cwd: '<%= widgetPath %>',