This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'iconv' | |
require 'rubygems' | |
require 'ipparse' | |
write_now = Time.now | |
counts = {} | |
comma = ',' | |
open "member22.csv" do |f| | |
loop do |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// extend scala.xml.NodeSeq to support xpath with attr | |
// call-seq: ex.RichNodeSeq(<a id="2"/><a/>) \ "a[id=2]" | |
package ex | |
import scala.xml._ | |
case class RichNodeSeq(nodeSeq: NodeSeq) extends NodeSeq { | |
def theSeq = nodeSeq.theSeq | |
private val attrRe = """^\s*(.*)\s*\[\s*(.*)\s*=\s*(.*)\s*\]$""".r |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# regexps to check if a string is pure chinese | |
class String | |
# 20k chars | |
CHINESE_UCS2 = /^(?: | |
[\x4e-\x9e][\x00-\xff] | |
|\x9f[\x00-\xa5] | |
)+$/xn | |
# 20k chars | |
CHINESE_UTF8 = /^(?: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# state lexer | |
require 'strscan' | |
class StateLexer | |
attr_reader :state | |
class ScanError < StandardError; end | |
def initialize opts = {:states => []} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 99 bottles of beer | |
class Fixnum | |
def bottle | |
"#{self} bottles of beer". | |
sub(/^-1/,'99'). | |
sub(/^0/,'no more'). | |
sub(/^(1\ .+)s/, '\1') | |
end | |
def wall | |
"#{self.bottle} on the wall" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'state_machine' | |
class StateMachine::Machine | |
def par_event events, test_field, trans | |
i = 1 | |
# binary 11....1 | |
full = (1 << events.size) - 1 | |
events.each do |e| | |
j = i | |
event e do | |
transition(hash.merge(:if => (lambda{ |obj| |
NewerOlder