Skip to content

Instantly share code, notes, and snippets.

View jedediah's full-sized avatar

Jedediah Smith jedediah

View GitHub Profile
module Enumerable
# Skip the first n elements and return
# an Enumerator for the rest, or pass them
# in succession to the block, if given.
def skip n
if block_given?
each do |x|
if n > 0
n -= 1
else
module RegexpBuilder
module RegexpExt
class Builder
class RegexpSource
def initialize x
@src = if x.is_a? self.class
x.to_s
else
x
end
/* 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"
#!/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} "
/*
* 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 */
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
require 'gserver'
def listen port=9999, &block
Class.new GServer do
define_method :serve, &block
end.new(port).start
end
loop { puts eval(gets).inspect }
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
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}?",