Skip to content

Instantly share code, notes, and snippets.

View aviflombaum's full-sized avatar

Avi Flombaum aviflombaum

View GitHub Profile
@aviflombaum
aviflombaum / gist:11442
Created September 18, 2008 16:25 — forked from sudara/gist:11441
delegate: function(rules) {
return function(e) {
var target = $(e.target), parent = null;
for (var selector in rules) {
if (target.is(selector) || ((parent = target.parents(selector)) && parent.length > 0)) {
return rules[selector].apply(this, [parent || target].concat($.makeArray(arguments)));
}
parent = null;
}
}
#!/usr/bin/env ruby
#
# usage: script/server_restarter
#
# Rails autoloading, while nice in theory, frequently doesn't work. Since Rails 2.3+
# is so fast when completely reloading the server, I wrote this script to listen to the
# given directories, and kill/restart the server when any file is changed.
#
# It's quick, simple, and it reliably reloads your application when changes are made.
#
function enable_edit_mode(){
$('.is_editable').each(function(){
$(this).bind('click.edit_mode', function(e){
edit_element(this);
return false;
});
});
};
function edit_element(edititable_element) {
development: &global_settings
database: textual_development
host: 127.0.0.1
port: 27017
test:
database: textual_test
<<: *global_settings
production:
# include this in application controller
module Authentication
protected
# Inclusion hook to make #current_user and #signed_in?
# available as ActionView helper methods.
def self.included(base)
base.send :helper_method, :current_user, :signed_in?, :authorized? if base.respond_to? :helper_method
end
# Returns true or false if the user is signed in.
@aviflombaum
aviflombaum / date_formats.rake
Created March 28, 2012 20:49 — forked from lmarlow/date_formats.rake
Show available format strings for Date, DateTime, and Time objects in Rails
desc "Show the date/time format strings defined and example output"
task :date_formats => :environment do
now = Time.now
[:to_date, :to_datetime, :to_time].each do |conv_meth|
obj = now.send(conv_meth)
puts obj.class.name
puts "=" * obj.class.name.length
name_and_fmts = obj.class::DATE_FORMATS.map { |k, v| [k, %Q('#{String === v ? v : '&proc'}')] }
max_name_size = name_and_fmts.map { |k, _| k.to_s.length }.max + 2
max_fmt_size = name_and_fmts.map { |_, v| v.length }.max + 1
@aviflombaum
aviflombaum / new_bashrc.sh
Created August 11, 2012 09:52 — forked from josephwecker/new_bashrc.sh
Replace .bashrc, .bash_profile, .profile, etc. with something much more clean, consistent, and meaningful.
#!/bin/bash
# License: Public Domain.
# Author: Joseph Wecker, 2012
#
# Are you tired of trying to remember what .bashrc does vs .bash_profile vs .profile?
# Are you tired of trying to remember how darwin/mac-osx treat them differently from linux?
# Are you tired of not having your ~/.bash* stuff work the way you expect?
#
# Symlink all of the following to this file:
# * ~/.bashrc
@aviflombaum
aviflombaum / oo_jukebox.rb
Created October 18, 2012 00:53 — forked from joshrowley/oo_jukebox.rb
Object Oriented Jukebox (with Session class)
class Song
attr_accessor :name
@@song_library = []
def self.all
@@song_library
end
def initialize(name)
# You have software to take payment from a customer
# There are 4 ways to pay, and they are all very similar.
# One day, you are paying by cash, and you realize you never calculated the tax!
# So you went in to your code and added order.compute_tax to the pay_by_cash method.
# Everything was great, until you realized you forgot to add it to pay_by_check also!
#
# You fixed this bug already, but the same code is duplicated in many places,
# so the bug fix didn't get everything. Frustrated, you decide to refactor your code.
#
# You see a lot of duplciation, but unfortunately, right in the middle of each of these