Skip to content

Instantly share code, notes, and snippets.

View noahhendrix's full-sized avatar

Noah Hendrix noahhendrix

View GitHub Profile
@noahhendrix
noahhendrix / api.rb
Created December 22, 2011 09:38
Authenticating with Grape
module Todo
class API < Grape::API
use Rack::Session::Cookie
version 'v1', :format => :json
helpers do
def current_user
return nil if env['rack.session'][:user_id].nil?
@current_user ||= User.get(env['rack.session'][:user_id])
end
@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 / 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)))
#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 / date.js
Created March 12, 2012 05:06
Sensible additions to the JS date object
Date.prototype.get12Hours = function() {
return this.getHours() % 12 || 12;
};
Date.prototype.getMeridanIndicator = function() {
return this.getHours() >= 12 ? 'PM' : 'AM';
};
@noahhendrix
noahhendrix / Gemfile
Created March 25, 2012 02:24 — forked from mbleigh/Gemfile
Non-Rails Rackup with Sprockets, Compass, Handlebars, Coffeescript, and Twitter Bootstrap
source :rubygems
gem 'sprockets'
gem 'sprockets-sass'
gem 'sass'
gem 'compass'
gem 'bootstrap-sass'
gem 'coffee-script'
@noahhendrix
noahhendrix / .agignore
Last active February 28, 2017 21:59
dotfiles
log
tags
tmp
Octokit.configure do |c|
c.api_endpoint = 'https://git.521000.bestpany.com/api/v3'
c.web_endpoint = 'https://git.521000.bestpany.com/'
end
@noahhendrix
noahhendrix / recipe.md
Created October 25, 2012 18:12
How to Sync RubyTapas with Podcasts
  1. Open the iTunes subscription (itpc://rubytapas.dpdcart.com/feed)
  2. Authenticate with your Ruby Tapas username and password
  3. Plug in your device and select it from the Devices menu
  4. Open the Podcasts tab
  5. Enable "Sync Podcasts"
  6. Ensure that RubyTapas is included in the sync list
  7. Press Apply
  8. Enable Wi-Fi syncing to get the episodes without plugging into your computer (optional)

Note: iTunes Syncing only works with the Podcasts app (https://itunes.apple.com/us/app/podcasts/id525463029?mt=8)

@noahhendrix
noahhendrix / call.rb
Created December 13, 2012 18:44
Just playing around with call (from RubyTapas #35)
class Content
def initialize(options={})
@notifier = options.fetch(:notifier) {
->(user) { puts "#{user.name}, you won!" }
}
end
def choose_winner
winner = User.new
@notifier.call(winner)