Skip to content

Instantly share code, notes, and snippets.

View aereal's full-sized avatar

aereal aereal

View GitHub Profile
class Promise
def initialize(_type, &block)
@type = _type
@converter = block_given? ? block : proc {|value| @type.new(value) }
end
def validate(val)
@type === val or raise ArgumentError
end
@aereal
aereal / gist:919251
Created April 14, 2011 10:41
Jabber client which only do notify with Growl (requires 1.8.*)
#!/usr/bin/env ruby
require 'rubygems'
require 'pit'
require 'xmpp4r-simple'
def notify(title, msg='')
system("growlnotify '#{title}' -m '#{msg}'")
end
#!/usr/bin/env ruby
# vim:set ft=ruby:
require "optparse"
require "tmpdir"
OPTS = {}
OptionParser.new.instance_eval do
on('-d', '--dry') { OPTS[:dry] = true }
require "sinatra"
get "/:message" do
system "growlnotify -a 'Growl Remote Notification' -m '#{params[:message]' '#{request.host}'"
"OK\n"
end
@aereal
aereal / gist:1006196
Created June 3, 2011 11:09
OpenStruct better than Class with attr_accessor
class Hoge
attr_accessor :hoge, :fuga
end
a = Hoge.new; b = Hoge.new
a.foo = :bar; b.foo = :bar
p a == b # -> false
require 'ostruct'
// vim:set noet sw=3 ts=3 sts=3
import scala.util.parsing.combinator._
import java.io.FileReader
class XselfParser extends RegexParsers {
def expression: Parser[Any] = opt("(")~rep(identifier)~opt(")")
def identifier: Parser[Any] = rep("""[a-zA-Z0-9]""".r | symbol)
def symbol: Parser[Any] = "~" | "!" | "@" | "$" | "%" | "^" | "&" | "*" | "-" | "_" | "=" | "+" | "|" | ":" | "<" | ">" | "/" | "?"
}
diff --git a/access_hatena.js b/access_hatena.js
index 2f82fa1..b291b02 100644
--- a/access_hatena.js
+++ b/access_hatena.js
@@ -218,7 +218,8 @@ map ; :accesshatena
} else if (args.length == 2) {
var host = args[0].toString();
context.title = ["ID", "Page"];
- context.completions = [[ids[i], title.get(host, ids[i])] for (i in ids) if (ids.hasOwnProperty(i))];
+ var _completions = [[ids[i], title.get(host, ids[i])] for (i in ids) if (ids.hasOwnProperty(i))];
class ::Object
def func(name, &block)
self.class.send(:define_method, name, &block)
end
end
func :unko do |len| "unko".each_char.map {|ch| ch * len.to_i }.join end
unko 5 # -> "uuuuunnnnnkkkkkooooo"
@aereal
aereal / gist:1069207
Created July 7, 2011 09:50
Class local variable
class Foo
@x = :class_local_var
class << self
attr_accessor :x
end
end
Foo.x # -> :class_local_var
Foo.x = 1
@aereal
aereal / apache-cassandra.rb
Created August 1, 2011 08:49
Formula for Apache Cassandra 0.7
require 'formula'
class ApacheCassandra < Formula
url 'http://www.apache.org/dyn/closer.cgi?path=/cassandra/0.7.9/apache-cassandra-0.7.9-bin.tar.gz'
homepage 'http://cassandra.apache.org'
md5 '6c7ae6a2c2e58e72261fa1f7321696fb'
def install
(var+'lib/cassandra-0.7').mkpath
(var+'log/cassandra-0.7').mkpath