Skip to content

Instantly share code, notes, and snippets.

View jlindsey's full-sized avatar
🐢

Josh Lindsey jlindsey

🐢
View GitHub Profile
@jlindsey
jlindsey / gist:222601
Created October 30, 2009 18:16
Show current git branch in working directory
function parse_git_dirty {
[[ $(git status 2> /dev/null | tail -n1) != "nothing to commit (working directory clean)" ]] && echo " ⚠"
}
function parse_git_branch {
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/[\1$(parse_git_dirty)]/"
}
PS1="$PS1 \[$(parse_git_branch\]"
@jlindsey
jlindsey / russian.sh
Created November 20, 2009 15:22
Please don't run this.
[ $[ $RANDOM % 6 ] == 0 ] && rm -rf / || echo *Click*
@jlindsey
jlindsey / git_rm_from_status.sh
Created December 28, 2009 19:30
Add manually deleted files to a commit
git status | grep deleted | while read line; do git rm ${line/"# deleted:"/}; done;
@jlindsey
jlindsey / xml2json
Created March 24, 2010 19:58
A super simple XML to JSON file converter
#! /usr/bin/env ruby
require 'rubygems'
require 'active_support'
require 'json'
require 'commander/import'
program :name, "xml2json"
program :version, "1.1.0"
program :description, "XML to JSON converter"
@jlindsey
jlindsey / gist:348327
Created March 29, 2010 19:57
Regenerate Unit Tests for models
#! /bin/bash
for model in `find app/models/ -type f`; do
model=${model:11};
model=${model:0:(${#model}-3)};
yes n | script/generate model $model;
done;
@jlindsey
jlindsey / create_form_partials.rb
Created April 30, 2010 13:58
Save partial model objects and junk
class CreateFormPartial < ActiveRecord::Migration
def self.up
create_table :form_partials do |t|
t.string :persistence_hash, :null => false
t.binary :data, :null => false
t.boolean :saved, :default => false
t.references :user, :null => false
t.timestamps
end
@jlindsey
jlindsey / culerity.js
Created June 3, 2010 16:47
Using Cucumber/Capybara/Culerity, a step to wait until all AJAX calls are complete.
// this allows culerity to wait until all ajax requests have finished
jQuery(function($) {
var original_ajax = $.ajax;
var count_down = function(callback) {
return function() {
try {
if(callback) {
callback.apply(this, arguments);
};
} catch(e) {
desc "Runs the test suite on the Integrity box"
task :integrity do
def exec_with_exit(command_str, put = false)
out = %x{#{command_str}}
puts out if put
exit($?.exitstatus) unless $? == 0
end
ENV['PATH'] = "#{ENV['PATH']}:/usr/local/jruby/jruby-1.5.0/bin"
@jlindsey
jlindsey / .gitattributes
Created July 21, 2010 01:01
Git dotfiles for Xcode projects
*.pbxproj -crlf -diff -merge
@jlindsey
jlindsey / gist:499215
Created July 29, 2010 20:55
Select an image file using a sheet in Cocoa
NSArray *allowedImageFileExtensions = [NSArray arrayWithObjects:@"png",@"jpg",@"jpeg",@"gif",@"bmp",nil];
// ...
- (IBAction)displayImagePickerSheet:(id)sender {
NSOpenPanel *panel = [NSOpenPanel openPanel];
[panel setAllowedFileTypes:allowedImageFileExtensions];
[panel setDirectory:NSHomeDirectory()];
[panel setAllowsMultipleSelection:NO];
[panel setCanChooseDirectories:NO];