This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Appointment < ActiveRecord::Base | |
attr_reader :availability | |
def full? | |
availability < 1 | |
end | |
end | |
# And then in your view | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class BlankSlate | |
instance_methods.each { |m| undef_method m unless m =~ /^__/ } | |
end | |
class Delegated < BlankSlate | |
attr_reader :delegate | |
def initialize(delegate) | |
@delegate = delegate | |
end | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
escape ^t^t | |
startup_message off | |
hardstatus alwayslastline | |
hardstatus string "%?%{yk}%-Lw%?%{wb}%n*%f %t%?(%u)%?%?%{yk}%+Lw%?%{yk}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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\//) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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))))) |
OlderNewer