Skip to content

Instantly share code, notes, and snippets.

View altamic's full-sized avatar

Michelangelo Altamore altamic

View GitHub Profile
@mislav
mislav / config.ru
Created October 16, 2011 18:32
Shortest simplest sweetest web "hello {NAME}" in Ruby
run ->(e){ p=Hash[*e['QUERY_STRING'].split(/[&=]/)]; [200, {'Content-type'=>'text/html'}, ["Hello #{p['name']}!"]] }
# 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:
anonymous
anonymous / gist:878158
Created March 20, 2011 06:25
~/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
require 'socket'
require 'rubygems'
require 'redis'
UseRawSockets = false
s = TCPSocket.open("127.0.0.1",6379)
s.write("MONITOR\r\n")
if UseRawSockets
@jimweirich
jimweirich / fic
Created March 15, 2011 21:46
Find in Code
#!/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]+)$/
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|
# 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'] || '.'
@jimweirich
jimweirich / exceptions.rb
Created March 7, 2011 02:55
How to organize exceptions in your library
# 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
// 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 = {};
#!/bin/sh
=begin 2>/dev/null
exec ${RUBY_BIN:-ruby} -e"\$0='$0'; load '$0'" -- $@
=end
#!/usr/bin/env ruby
puts 123
# Examples:
#