Skip to content

Instantly share code, notes, and snippets.

View tie-rack's full-sized avatar

Christopher Shea tie-rack

View GitHub Profile
class Appointment < ActiveRecord::Base
attr_reader :availability
def full?
availability < 1
end
end
# And then in your view
class JsUnit < Thor
desc 'create_test_directory', 'Create the javascript test directory'
def create_test_directory
FileUtils.mkdir_p(test_path)
end
desc 'create_test_file FILE', 'Create a JsUnit test page for FILE'
def create_test_file(filename)
create_test_directory
# A few assumptions are made here:
#
# 1. You want your javascript tests in test/javascript
# 2. Your jsunittest.js file is called that (you've stripped the version)
# 3. You've got a jsunittest.css file in the same place
# 4. You've set JSUNITTEST as the path to where the jsunittest files live
#
# Run it like this: thor jsunittest:test path/to/your/js.js
require 'pathname'
class BlankSlate
instance_methods.each { |m| undef_method m unless m =~ /^__/ }
end
class Delegated < BlankSlate
attr_reader :delegate
def initialize(delegate)
@delegate = delegate
end
escape ^t^t
startup_message off
hardstatus alwayslastline
hardstatus string "%?%{yk}%-Lw%?%{wb}%n*%f %t%?(%u)%?%?%{yk}%+Lw%?%{yk}"
# Run the little Sinatra app on port 3000 and the big Rails app on
# port 3001. Run this file and hit them both at port 4000.
require 'rubygems'
require 'rack/proxy'
require 'thin'
class LittleProxy < Rack::Proxy
def rewrite_env(env)
if env['PATH_INFO'].match(/^\/little\//)
#!/usr/bin/env ruby
require 'yaml'
begin
YAML.load(STDIN)
puts '<h1 style="color: green;">GOOD</h1>'
rescue Exception => e
puts '<h1 style="color: red;">BAD</h1>'
puts e.message
@tie-rack
tie-rack / xkcd.com.js
Created March 28, 2011 19:13
dotjs for adding the title text of XKCD comics on the page (no more tooltip for me!)
var comic = $("div.s img[title]");
var titleP = $("<p></p>");
titleP.css({"font-variant": "normal",
"border": "1px solid yellow",
"padding": "1em",
"background-color": "#FFFFCC"});
titleP.text(comic.attr("title"));
comic.after(titleP);
@tie-rack
tie-rack / gi.sh
Last active December 14, 2015 13:38
I'm always typing `gi tbranch` when I mean to type `git branch`. So have this in my PATH with the name `gi`.
#!/bin/zsh
COMMAND=$1
COMMAND=${COMMAND[2,-1]}
ARGUMENTS=$@[2,-1]
echo "\e[33mYou typed: \e[31mgi $@\e[0m"
echo "\e[33mYou meant: \e[32mgit $COMMAND $ARGUMENTS\e[0m"
echo
(defn example-middleware [handler]
(fn [request]
(let [now (System/currentTimeMillis)
modified-request (assoc-in request [:headers "received-at"] now)
response (handler modified-request)]
(assoc-in response
[:headers "processing-time"]
(- (System/currentTimeMillis) now)))))