Skip to content

Instantly share code, notes, and snippets.

View ethagnawl's full-sized avatar
🐢

Pete Doherty ethagnawl

🐢
View GitHub Profile
@ethagnawl
ethagnawl / Gemfile
Created November 14, 2012 08:08
Conditionally Execute JavaScript in the Asset Pipeline
# https://github.com/gazay/gon
gem 'gon'
@ethagnawl
ethagnawl / onerror.coffee
Last active December 9, 2015 17:18 — forked from anonymous/gist:4302682
An onerror handler that's a helluva lot more useful than `... catch(e) { alert(e) }`.You can easily hook this into a custom Google Analytics event to log your app's errors. Inspired by: http://bytes.com/topic/javascript/answers/90742-try-catch-error-handling-display-line-number
onerror = (err, file, line) ->
logger """ # console.log, alert, whatever
The following error occured: #{err}
In file: #{file}
At line: #{line}
"""
@ethagnawl
ethagnawl / gist:4303329
Created December 16, 2012 04:31
Instagram UIWebView UserAgent string
Instagram 3.2.0 (iPhone5,2; iPhone OS 6.0.1; en_US) AppleWebKit/420+
# 420, bro
- classes can be no longer than 100 lines
- methods can be no longer than 5 lines
- methods cannot accept more than 4 parameters (no gigantic hashes)
- controllers cannot instantiate more than 1 object
- views cannot know about more than 1 instance variable
- views should only send messages to that variable (no Demeter violations)
- rules are meant to be broken if by breaking them you produce better code
@ethagnawl
ethagnawl / gist:4700461
Created February 3, 2013 03:37
Notes on Vim Registers
"A(cap reg name) appends to register
append to macro stored in a with qAo
paste from unnamed ""p
execute code in unnamed register with @"
_ reg is blackhole - use to avoid clobbering current unnamed register
@ethagnawl
ethagnawl / gist:5207479
Last active December 15, 2015 05:18
Mass assign harvestapp.com invoice unit price input values.
var HOURLY_RATE = 9999.99; // lulz
var inputs = [].slice.call(document.querySelectorAll('.price'));
inputs.forEach(function (price) {
if (price.children[0]) {
price.children[0].value = HOURLY_RATE;
}
});
@ethagnawl
ethagnawl / nth_letter.rb
Created March 20, 2013 20:44
DSL for querying nth_letter of string.
def self.method_missing(method, *args)
number_dictionary = {
first: 1,
second: 2,
third: 3,
fourth: 4,
fifth: 5,
sixth: 6,
seventh: 7,
eigth: 8,
@ethagnawl
ethagnawl / gist:5209401
Last active December 15, 2015 05:29
EasyLoader is a cross-browser, mobile-friendly, customizable loading pacifier. http://jsfiddle.net/ethagnawl/6LJW6/1/
class EasyLoader
constructor: (@DOT = '.', @TIMEOUT_LENGTH = 400, @MAX_NUMBER_OF_DOTS = 3) ->
@loading_message_timeout = true
render: ->
style_hash =
'left': '0'
'padding': '12px'
'position': 'absolute'
'text-align': 'center'
@ethagnawl
ethagnawl / log.js
Created April 30, 2013 00:23
Cross-browser log utility function
window.log = (function () {
if (window.console && window.console.log) {
return function (message) {
console.log(message);
}
} else {
return function (message) {
alert(message);
}
}
@ethagnawl
ethagnawl / gist:5622142
Created May 21, 2013 18:33
Using locals in views. Inspired by @henrik.
def show
locals item: Item.find(params[:id])
end
def locals(hash)
render locals: hash
end