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
# http://pragdave.me/blog/2007/12/30/pipelines-using-fibers-in-ruby-19/ | |
# http://pragdave.me/blog/2008/01/01/pipelines-using-fibers-in-ruby-19part-ii/ | |
class PipelineElement | |
attr_accessor :source | |
def initialize | |
@transformer ||= method(:transform) | |
@filter ||= method(:filter) |
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
deb http://ftp.sjtu.edu.cn/ubuntu/ trusty main restricted universe multiverse | |
deb http://ftp.sjtu.edu.cn/ubuntu/ trusty-updates main restricted universe multiverse | |
deb http://ftp.sjtu.edu.cn/ubuntu/ trusty-security main restricted universe multiverse | |
deb-src http://ftp.sjtu.edu.cn/ubuntu/ trusty main restricted universe multiverse | |
deb-src http://ftp.sjtu.edu.cn/ubuntu/ trusty-updates main restricted universe multiverse | |
deb-src http://ftp.sjtu.edu.cn/ubuntu/ trusty-security main restricted universe multiverse |
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
#!/usr/bin/env ruby | |
def to_utf8(codepoint) | |
case codepoint | |
when (0..0x7F) | |
[codepoint] | |
when (0x80..0x7FF) | |
[ | |
0b11000000 + (codepoint >> 6), | |
0b10000000 + (codepoint & 0b111111) |
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
#!/usr/bin/env ruby | |
def from_utf8(bytes) | |
def assert_cont_byte(*bytes) | |
bytes.each do |b| | |
raise UTF8Error, "not a valid continuation byte: #{b}" unless (128..191).include?(b) | |
end | |
end | |
i = 0 |
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
#!/usr/bin/env ruby | |
encodings = Encoding.list.each_with_object({}) do |enc, full_list| | |
full_list[enc.name] = [enc.name] | |
end | |
Encoding.aliases.each do |alias_name, base_name| | |
fail "#{base_name} #{alias_name}" unless encodings[base_name] | |
encodings[base_name] << alias_name | |
end |
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
# Regional Indicator Symbol | |
puts "\u{1f1fa 1f1f8}" # US | |
puts "\u{1f1ef 1f1f5}" # JP | |
puts "\u{1f1e8 1f1f3}" # CN | |
puts "\u{1f1ec 1f1e7}" # GB | |
puts "\u{1f1e9 1f1ea}" # DE | |
puts "\u{1f1eb 1f1f7}" # FR | |
puts "\u{1f1ea 1f1f8}" # ES | |
puts "\u{1f1f7 1f1fa}" # RU |
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
#!/usr/bin/env ruby | |
module PJ | |
module Parser | |
extend self | |
def decode(string) | |
tokens = lex(string) | |
raise ParseError, "too few tokens" if tokens.length < 2 |
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
class String | |
def to_proc | |
lambda { |obj| obj.send(self) } | |
end | |
end | |
p ['a'].map(&"upcase") | |
# => ["A"] |
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 File.expand_path(File.dirname(__FILE__) + '/neo') | |
# Greed is a dice game where you roll up to five dice to accumulate | |
# points. The following "score" function will be used to calculate the | |
# score of a single roll of the dice. | |
# | |
# A greed roll is scored as follows: | |
# | |
# * A set of three ones is 1000 points | |
# |
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
module AttributeAddition | |
def attribute(att, &block) | |
if att.is_a?(Hash) | |
att.each do |a, default| | |
define_attribute(a, default) | |
end | |
else | |
define_attribute(att, &block) | |
end | |
end |
OlderNewer