Skip to content

Instantly share code, notes, and snippets.

@thadd
thadd / checkbox_select.js
Created November 18, 2009 21:36
JQuery: How to select/deselect all checkboxes
$(function() {
$('#select_all_check').click(function(){
$('input:checkbox').attr('checked', $(this).attr('checked'));
});
});
@thadd
thadd / application_controller.rb
Created November 26, 2009 17:17
How to scope all of a model's finders based on a user preference
class ApplicationController < ActionController::Base
around_filter :check_for_prefers_recent
protected
def check_for_prefers_recent
if current_user && current_user.show_recent_only?
Gift.scope_to_recent do
yield
end
@thadd
thadd / git_prompt.sh
Created January 13, 2010 19:21
Embed current git branch into prompt
typeset -ga precmd_functions
precmd_functions+='update_git_branch_prompt'
update_git_branch_prompt() {
RPROMPT=$(git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/')
}
let s:save_cpo = &cpo
set cpo&vim
set listchars=eol:\|,trail:_,tab:>-
colors peachpuff
set printoptions=paper:letter
set guifont=Inconsolata:h14
set columns=198
@thadd
thadd / branch-prompt.sh
Created March 17, 2011 12:27
Show your current git branch in a right-hand prompt in zsh
typeset -ga precmd_functions
precmd_functions+='update_git_branch_prompt'
update_git_branch_prompt() {
RPROMPT=$(git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/')
}
@thadd
thadd / paginate.rb
Created July 17, 2012 18:02
Update for paginate liquid drop in Locomotive Editor
pagination = {}
pagination['collection'] = collection.send(:paginate, {
:page => context['current_page'],
:per_page => @per_page })
pagination['current_page'] = pagination['collection'].current_page
pagination['per_page'] = pagination['collection'].per_page
pagination['total_entries'] = pagination['collection'].total_entries
pagination['next_page'] = pagination['collection'].next_page
pagination['previous_page'] = pagination['collection'].previous_page
@thadd
thadd / away_from_home.applescript
Created July 29, 2013 22:36
This Applescript checks to see if you're away from home and sets OS X to require a password if you're out. If you're at home, no password is required. It requires Location Helper to work (free on the app store). I also recommend Lingon to make it easy to setup the repeating task in launchd. Just set your home address and run this periodically.
tell application "Location Helper"
set home_address to geocode address "123 Main St., Anytown, US"
set location to location of geometry of item 1 of results of home_address
set home_coordinates to {lat of location, lng of location}
set distance to get distance from coordinates home_coordinates
if distance > 500 then
cd "`osascript -e 'tell application "Finder"' -e 'set myname to POSIX path of (target of window 1 as alias)' -e 'end tell' 2>/dev/null`"
@thadd
thadd / repo-clone.sh
Created December 6, 2018 17:23
Clones all branches from one remote to another. Replace `destremote` and `sourceremote` as appropriate.
# Copies all branches from one git remote to another
git push destremote 'refs/remotes/sourceremote/*:refs/heads/*'