This file contains hidden or 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 Filter | |
| class << self | |
| def filters | |
| @filters ||= {} | |
| end | |
| def add(name, &code) | |
| filters[name] = code | |
| end | |
| end |
This file contains hidden or 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
| # Gviz sample: | |
| # Graphviz Example: Undirected Graph Clusters | Graphviz - Graph Visualization Software | |
| # http://www.graphviz.org/content/fdpclust | |
| require "gviz" | |
| Graph(:G, :graph) do | |
| global layout:'fdp' | |
| node :e | |
| subgraph(:clusterA) do | |
| route :a => :b |
This file contains hidden or 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
| #election.rb | |
| require "gviz" | |
| header, *candidates = DATA.readlines.map(&:split) | |
| Graph do | |
| global layout:'fdp' | |
| nodes shape:"plaintext", style:"filled", fillcolor:"white" | |
| node :election, shape:'doublecircle', label:"2014年\n東京都知事選挙", fillcolor:'orange' |
This file contains hidden or 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 "RMagick" | |
| include Magick | |
| images = Dir.glob("*.png").sort_by { |n| n.sub(/\D+/,'').to_i } | |
| anim = ImageList.new(*images) | |
| anim.delay = 40 | |
| anim.write("anpan.gif") |
This file contains hidden or 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
| # Batman equation for Gviz | |
| # [geometry - Is this Batman equation for real? - Mathematics Stack Exchange](http://math.stackexchange.com/questions/54506/is-this-batman-equation-for-real 'geometry - Is this Batman equation for real? - Mathematics Stack Exchange') | |
| def f1(x) | |
| Math.sqrt(1 - (x/7.0)**2) * 3 | |
| end | |
| def f2(x) | |
| (x/2.0).abs - ((3*Math.sqrt(33)-7)/112.0)*x**2 - 3 + Math.sqrt((1 - ((x.abs - 2).abs - 1)**2).abs) | |
| end |
This file contains hidden or 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
| # Translate Let it Snow in the Terminal from Ruby to Ruby | |
| # | |
| # Original code: | |
| # ruby -e 'C=`stty size`.scan(/\d+/)[1].to_i;S=["2743".to_i(16)].pack("U*");a={}; \ | |
| # puts "\e[2J";loop{a[rand(C)]=0;a.each{|x,o|;a[x]+=1;print "\e[#{o};#{x}H \ | |
| # \e[#{a[x]};#{x}H#{S} \e[0;0H"};$stdout.flush;sleep 0.1}' | |
| # | |
| # Let it Snow in the Terminal of Mac OS X with This Command | |
| # http://osxdaily.com/2013/12/06/snow-terminal-mac-os-x-command/ | |
| # |
This file contains hidden or 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 F | |
| attr_reader :name, :path, :level | |
| def initialize(name, level=0) | |
| @name = File.basename(name) | |
| @path = File.expand_path(name) | |
| @level = level | |
| end | |
| def to_s | |
| "F: #{name}" |
This file contains hidden or 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
| # Draw Ruby universe with gviz(graphviz wrapper in Ruby) | |
| # try `gviz build [THIS_FILE]` at terminal | |
| classes = ObjectSpace.each_object(Class) | |
| .reject { |k| "#{k}".match /Gem|Thor|Gviz/ } | |
| global layout:'fdp' | |
| nodes style:'filled', colorscheme:'purd6' | |
| edges color:'maroon' |
This file contains hidden or 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
| # coding=utf-8 | |
| # This is an edited version of @ne_sachirou's String::INFINITY | |
| # Range 'a' .. String::INFINITY (Ruby) - c4se記:さっちゃんですよ☆ | |
| # http://c4se.hatenablog.com/entry/2013/10/01/010305 | |
| # Diffs: | |
| # - Define StringInfinity#inspect | |
| # - Use Module#prepend | |
| # - Replace '==' to 'eqlual?' at #size to fix when last=='' passed | |
| # - Fix Range#size test |
This file contains hidden or 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 AutoAttrSet | |
| def new(*args, &blk) | |
| obj = allocate | |
| obj.send(:initialize, *args, &blk) | |
| set_instance_variables(obj, args) | |
| obj | |
| end | |
| private | |
| def set_instance_variables(obj, args) |