Skip to content

Instantly share code, notes, and snippets.

@yugui
yugui / gist:1724
Created July 23, 2008 13:39
Decorator for Ruby, inspired by Python
class Module
def declare(decorator, *args)
orig_method_added = method(:method_added)
metaclass = (class << self; self end)
defined_methods = []
metaclass.send(:define_method, :method_added) do |name|
orig_method_added.call(name)
defined_methods << name
end
begin
@yugui
yugui / gist:30428
Created November 30, 2008 12:47
helper methods to generate mdoc from OptionParser in Ruby
require 'optparse'
class OptionParser
def list_opts(prior_opts)
opts = enum_for(:visit, :tap).map(&:list).flatten(1)
prior_opts = opts.select{|opt| opt.long.any?{|name| prior_opts.include?(name)} }
opts -= prior_opts
simple_opts = opts.select{|opt| !opt.short.empty? && opt.arg.nil? }.sort_by{|x| x.short.sort.first}
opts -= simple_opts
@yugui
yugui / gist:33963
Created December 9, 2008 16:47
How meta^n classes work in Ruby 1.9. This requires http://github.com/yugui/evil-ruby/tree/master .
require 'test/unit'
require '/Users/yugui/dev/evil-ruby/lib/evil'
class Object
alias_method :c, :actual_class
end
class Class
alias_method :s, :actual_superclass
end
class Foo; end
@yugui
yugui / x
Created January 28, 2009 03:50
CmdUtils.CreateCommand({
name: "ruby-dev",
takes: {"number": noun_arb_text},
execute: function(number) {
if (number && number.text && number.text.length != 0) {
window.content.location.href = "http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-dev/" + number.text;
} else {
window.content.location.href = "http://blade.nagaokaut.ac.jp/ruby/ruby-dev/index.shtml";
}
}
@yugui
yugui / gist:110482
Created May 12, 2009 13:37
lists up all committers of ruby
#!/bin/sh
svn log -q http://svn.ruby-lang.org/repos/ruby/ | grep -v '^--' | cut -d'|' -f 2 | sed 's/ //g' | sort | uniq
CC="ccache gcc" ../../mri/configure --prefix=~/local --program-suffix=-1.9.1
@yugui
yugui / apcupsd.patch
Created April 18, 2010 14:12
patch for apcupsd in order to make it a solaris pkg
diff --git a/.gitignore b/.gitignorenew file mode 100644
index 0000000..01bee7b
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,30 @@
+.obj
+.deps
+*.a
+config.log
+config.out
@yugui
yugui / getopt.c.diff
Created April 18, 2010 14:16
patch for apcupsd on AIX 5.2
--- src/lib/getopt.c.orig 2010-04-18 08:54:21.000000000 -0500
+++ src/lib/getopt.c 2010-04-18 08:54:34.000000000 -0500
@@ -57,7 +57,9 @@
#ifdef __GNU_LIBRARY__
/* Don't include stdlib.h for non-GNU C libraries because some of them
contain conflicting prototypes for getopt. */
+#ifndef _AIX
#include <stdlib.h>
+#endif
#endif /* GNU C library. */
#!/bin/sh
GIT_DIR=`git rev-parse --git-dir`
sqlite3 $GIT_DIR/revisions.sqlite \
'create table revisions(svn integer primary key, hash char(40) not null); alter table revisions add index i_hash(hash);'
trait ExpressionTrueness[T] {
def myElse(then: => T)
}
class ExpressionTruth[T](obj: T) extends ExpressionTrueness[T] {
def myElse(then: => T) = obj
}
class ExpressionFalsity[T] extends ExpressionTrueness[T]() {
def myElse(then: => T) = then