Skip to content

Instantly share code, notes, and snippets.

View jedediah's full-sized avatar

Jedediah Smith jedediah

View GitHub Profile
require 'sinatra/base'
require 'fiber'
module Sinatra
module Strands
REQUEST_METHODS = [:get,:put,:post,:delete]
class Strand
def initialize *args, &block
@secure_id = object_id # TODO: not actually secure
@fiber = Fiber.new do
require 'sinatra'
require 'sinatra/strands'
require 'haml'
helpers do
def message locals={}
haml :message,
:locals => {:uri => strand_uri }.merge(locals)
end
end
def delete
text = "Enter the name of the record you want to delete"
loop do
action, record = input :text => text,
:buttons => {:delete => "Delete", :cancel => "Cancel"}
break if action == :cancel
if record_exist? record
delete_record record if dialog :text => "Really delete #{record}?",
module AutoBang
def method_missing meth, *args, &block
if meth =~ /^(.*)!$/ and respond_to?(m = $1)
replace send(m, *args, &block)
else
super
end
end
end
loop { puts eval(gets).inspect }
require 'gserver'
def listen port=9999, &block
Class.new GServer do
define_method :serve, &block
end.new(port).start
end
class Object
def to_ast; self; end
end
module DAL
class Call
attr_accessor :message, :name, :args, :block
def initialize context, name, *args, &block
@context = context
@name = name
/*
* This is the CSS found in embedded gists from Github.
* The descriptions are Ruby specific but other languages
* likely use similar schemes.
*/
.gist /* entire embedded box */
#gist-? /* specific .gist box, ? is numeric gist id */
.gist-file /* one file */
.gist-data /* code box */
#!/usr/bin/ruby
host = `hostname`.chomp
user = ENV['USER'] || '???'
pwd = Dir.pwd
term = ENV['TERM'] || ''
x = ''
x << "\e]0;#{pwd}\a" if term =~ /xterm|rxvt/ # set window title
x << "\e[1;36;44m #{user}@#{host} \e[1;33;44m#{pwd} "
/* Programmed in 2009 by Jedediah Smith
* For benevolent use only.
*
* Using Visual C 2005 or later, build with:
*
* cl devdays.c /D _CONSOLE /link user32.lib /SUBSYSTEM:CONSOLE
*
* Run:
*
* devdays.exe HHMM "DevDays will resume in %s"