Skip to content

Instantly share code, notes, and snippets.

//sometimes, you just want the copy inside an element.
function $T(element) {
var t = $(element);
return t == null ? t : t.innerHTML.gsub(/<\/?[^>]*>/, '');
}
//is fetching the innerHTML bad form? Most of the time, yeah.
function $M(element) {
var m = $(element);
return m == null ? m : m.innerHTML;
/*
* @author jnf http://github.com/jnf
* other_select, when attached to a select box, pops a sibling input field with similar
* attributes. Use it to record user input that falls outside the options provided in a
* select box.
*/
$.fn.other_select = function(options) {
var defaults = {
speed: 'normal', //rate at which the alternate input field appears/disappears
nameSuffix: '_other', //suffix appended to the alternate input's name attribute
@jnf
jnf / zepto.scrollBoth.js
Created October 25, 2012 16:22
Extending ZeptoScroll (https://github.com/suprMax/ZeptoScroll) to support horizontal and vertical scrolling.
;(function($) {
var interpolate = function (source, target, shift) {
return (source + (target - source) * shift);
};
var easing = function (position) {
return (-Math.cos(position * Math.PI) / 2) + .5;
};
$.scrollBoth = function(XY, duration, easingF) {
@jnf
jnf / story.rb
Created November 14, 2012 05:42
Color layering for Stories
class Story < ActiveRecord::Base
...
before_save :setColor
...
private
def setColor
@jnf
jnf / pgpass.rake
Last active December 11, 2015 11:38
Example rake task to generate ~/.pgpass based on info fetched from heroku:config
namespace :db do
require 'uri'
desc "Uses heroku:config for APP to forcefully create ~/.pgpass"
task :create_pgpass do
app = ENV['APP'] || 'whatever-your-default-app-is'
uri = URI(`heroku config:get DATABASE_URL -a #{app}`)
entry = "*:5432:#{uri.path.gsub /\//, ''}:#{uri.user}:#{uri.password}"
`echo '#{entry}' > ~/.pgpass; chmod 0600 ~/.pgpass`
end
@jnf
jnf / .gitconfig
Last active December 12, 2015 03:48
My Favorite .gitconfig settings/aliases/whatevs
[alias]
pretty = log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --date=relative
ll = log --stat --abbrev-commit
d = diff --color-words
s = status
[color]
ui = auto
[color "branch"]
//generic tag helpers
Handlebars.registerHelper('generic_tag', function(tag, text, options) {
var attrs = [];
for(var prop in options.hash) { attrs.push(prop + '="' + options.hash[prop] + '"'); }
return new Handlebars.SafeString( "<" + tag + " " + attrs.join(" ") + ">" + text + "</" + tag + ">" );
});
Handlebars.registerHelper('generic_selfclosing_tag', function(tag, options) {
@jnf
jnf / ruby_warrior_lvl9.rb
Last active January 29, 2016 03:30
My code for level 9 of Ruby Warrior (https://www.bloc.io/ruby-warrior#/)
class Player
def play_turn(warrior)
@prev_health ||= 20
@warrior = warrior
@space = @warrior.feel
feel_it_out
@prev_health = warrior.health
end
@jnf
jnf / config.rb
Last active December 21, 2015 18:29
Strange middleman rendering.
helpers do
def icon_tag(icon, copy)
tag(:i, class: icon) + ' ' + copy
end
end
@jnf
jnf / level_2.rb
Created July 27, 2014 05:54
Ruby Warrior, Intermediate
class Player
def play_turn(warrior)
@warrior = warrior
@preferred_direction = @warrior.direction_of_stairs
wat_do?
end
protected