Skip to content

Instantly share code, notes, and snippets.

View noahhendrix's full-sized avatar

Noah Hendrix noahhendrix

View GitHub Profile
#functions
#is the branch dirty, if so echo a *
function parse_git_dirty {
[[ $(git status 2> /dev/null | tail -n1) != "nothing to commit (working directory clean)" ]] && echo "*"
}
#if in a git repo echo branch name and dirty status
function parse_git_branch {
ref=$(git symbolic-ref HEAD 2> /dev/null) || return
echo "("${ref#refs/heads/}"`parse_git_dirty`)"
@noahhendrix
noahhendrix / gist:1757085
Created February 7, 2012 04:01
Heuristic Search on 8 Tile Puzzles
#lang racket
(require data/heap)
(require racket/trace)
;globals
(define GOAL (list 1 2 3 4 5 6 7 8 0))
(define GOAL-COORDINATES (list
(list 0 0) (list 0 1) (list 0 2)
(list 1 0) (list 1 1) (list 1 2)
(list 2 0) (list 2 1) (list 2 2)))
@noahhendrix
noahhendrix / api.rb
Created January 4, 2012 21:53
API Spec
module Todo
class API < Grape::API
use Rack::Session::Cookie
version 'v1', :format => :json
resource do
http_basic do |username, password|
User.authenticate(username, password)
end
@noahhendrix
noahhendrix / task_list_test.rb
Created December 16, 2011 06:43
Testing with datamapper
describe TaskList do
let(:list) { TaskList.new }
let(:todo) { mock('todo').as_null_object }
describe '#tasks' do
context 'without tasks' do
it 'returns an empty array' do
list.tasks.should be_empty
end
end
@noahhendrix
noahhendrix / employees_controller_test.rb
Created September 29, 2011 20:41
Testing a regular user can not create a user
require 'test_helper'
require 'clearance/testing'
class EmployeesControllerTest < ActionController::TestCase
test "an ASM can not create a user" do
sign_in
post :create, :employee => { :name => 'Feed Store' }
assert_raise CanCan::AccessDenied
end
@noahhendrix
noahhendrix / message.rb
Created September 2, 2011 06:50
Message Example
class Message < ActiveRecord::Base
belongs_to :recipient, :class => 'User'
belongs_to :sender, :class => 'User'
end
@noahhendrix
noahhendrix / style.css
Created July 28, 2011 18:52
Multiple backgrounds in CSS3
html, body { min-height: 100%; } /* force the footer to always be at the bottom */
body {
background:
url(layout/header.jpg) no-repeat scroll center top,
url(layout/header-bg.jpg) repeat-x scroll left top, /* allows screen to be resized w/o eventual cutoff */
url(layout/footer.jpg) no-repeat scroll center bottom,
url(layout/footer-bg.jpg) repeat-x scroll left bottom; /* allows screen to be resized w/o eventual cutoff */
}
@noahhendrix
noahhendrix / _search.html.erb
Created July 21, 2011 17:56
Ransack with Polymorphic Relationships
<%= search_form_for(@report.search, :url => report_path('sales', 'by_contact')) do |f| %>
<div class="input string optional">
<%= f.label :aggregator_of_User_type_name_eq, 'Name' %>
<%= f.text_field :aggregator_of_User_type_name_eq %>
</div>
<%= f.submit %>
<% end %>
@noahhendrix
noahhendrix / db.rake
Created July 11, 2011 00:03
My favorite custom Rake task for all new Rails projects
#lib/tasks/db.rake
namespace :db do
desc 'Drops the DB, migrates it, and finally seeds it'
task :reload => [:drop, :migrate, :seed]
end
class CreateProducts < ActiveRecord::Migration
def self.up
create_table :products do |t|
t.string :title
t.text :description
t.string :image_url
t.decimal :price, :precision => 8, :scale => 2
t.timestamps
end