This file contains hidden or 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 ->(e){ p=Hash[*e['QUERY_STRING'].split(/[&=]/)]; [200, {'Content-type'=>'text/html'}, ["Hello #{p['name']}!"]] } |
This file contains hidden or 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
# These are my notes from the PragProg book on CoffeeScript of things that either | |
# aren't in the main CS language reference or I didn't pick them up there. I wrote | |
# them down before I forgot, and put it here for others but mainly as a reference for | |
# myself. | |
# assign arguments in constructor to properties of the same name: | |
class Thingie | |
constructor: (@name, @url) -> | |
# is the same as: |
This file contains hidden or 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
~/projects/mirah ➔ tail -17 examples/dynamic.mirah # Example of using a dynamic type in a method definitiondef foo(a:dynamic) | |
puts "I got a #{a.getClass.getName} of size #{a.size}" | |
end | |
class SizeThing | |
def initialize(size:int) | |
@size = size | |
end | |
def size |
This file contains hidden or 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
require 'socket' | |
require 'rubygems' | |
require 'redis' | |
UseRawSockets = false | |
s = TCPSocket.open("127.0.0.1",6379) | |
s.write("MONITOR\r\n") | |
if UseRawSockets |
This file contains hidden or 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 | |
# -*- ruby -*- | |
begin | |
require 'rubygems' | |
rescue LoadError | |
end | |
exts = ['.rb', '.rhtml', '.erb', '.builder', '.haml', '.css', '.coffee' ] | |
if ARGV[0] =~ /^(\+|\.[a-zA-Z0-9]+)$/ |
This file contains hidden or 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
require 'rubygems' | |
require 'session' | |
bash = Session::Bash.new | |
command = 'ruby -e"STDOUT.sync = true; loop{ puts Time.now; sleep(rand) }"' | |
bash.execute command do |stdout, stderr| |
This file contains hidden or 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 daemon method that blocks until the grandchild is ready | |
# | |
# sending the pid up a pipe (grandchild -> child -> parent) | |
# | |
def daemon(options = {}, &block) | |
# setup | |
# | |
raise(ArgumentError, 'no block!') unless block | |
chdir = options[:chdir] || options['chdir'] || '.' |
This file contains hidden or 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
# Suppose you were designing a library named "Zippo". | |
# How would you organize the exceptions thrown by the library. | |
# Option 1 | |
# All library errors inheriting from a common base | |
module Zippo | |
class ZippoError < StandardError; end | |
class ZippoArgumentError < ZippoError; end | |
class ZippoTypeError < ZippoError; end |
This file contains hidden or 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
// Place your application-specific JavaScript functions and classes here | |
// This file is automatically included by javascript_include_tag :defaults | |
// | |
if(!window.jq && window.jQuery){ | |
var jq = jQuery; | |
}; | |
if(!window.App){ | |
window.App = {}; |
This file contains hidden or 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/sh | |
=begin 2>/dev/null | |
exec ${RUBY_BIN:-ruby} -e"\$0='$0'; load '$0'" -- $@ | |
=end | |
#!/usr/bin/env ruby | |
puts 123 | |
# Examples: | |
# |