Skip to content

Instantly share code, notes, and snippets.

@melborne
melborne / Hilite.rb
Created July 23, 2008 01:41
make a html file with syntax highlighting
#!/usr/bin/env ruby
require "rubygems"
require "uv"
class Hilite
BGCOLORS = {"all_hallows_eve" => {:bg => '#000000', :fg => '#ffffff'},
"amy" => {:bg => '#200420', :fg => '#d1d0ff'},
"blackboard" => {:bg => '#0d1021', :fg => '#f8f8f8'},
"brilliance_black" => {:bg => '#0d0d0d', :fg => '#cccccc'},
"brilliance_dull" => {:bg => '#0a0a0a', :fg => '#cdcdcd'},
@melborne
melborne / animator.rb
Created July 24, 2008 01:13
some ruby_Shoes sample codes
@app = Shoes.app do
img0 = ask_open_file #select a first image in sequence.
NUM_IMGS = 5
imgs = []
NUM_IMGS.times do |n|
imgs << img0.sub(/\d+/) { |m| n }
end
background black
@melborne
melborne / election.rb
Last active August 29, 2015 13:55
HTML-like labels sample for Gviz
#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'
# 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
@melborne
melborne / filter.rb
Last active August 29, 2015 13:57
Pipeline in Ruby
class Filter
class << self
def filters
@filters ||= {}
end
def add(name, &code)
filters[name] = code
end
end
# use benchmark_suite
# https://github.com/evanphx/benchmark_suite
# -*- encoding: utf-8 -*-
require 'benchmark/ips'
class Character < Struct.new(:name, :level, :point)
def to_s
"%s:\tlv:%d\tpt:%d" % values
end
end
require "./onetime"
module CoreExt
refine String do
def ~
margin = scan(/^ +/).map(&:size).min
gsub(/^ {#{margin}}/, '')
end
end
end
@melborne
melborne / proc_compressor.rb
Created April 26, 2014 10:35
Yet Another Proc Composer in Ruby
class ProcCompressor
def initialize(n)
@proc = proc.curry(n+1)
end
def <<(arg)
@proc = @proc[arg]
Proc===@proc ? self : @proc
end
require "named_emoji"
class Symbol
def ~
to_s
.split
.map { |w| NamedEmoji.emojis[w.intern.downcase] || w }
.join(" ")
end
end
@melborne
melborne / collections.ja.md
Last active August 29, 2015 14:01
Jekyll Collections日本語版
layout title prev_section next_section permalink
docs
コレクション
variables
datafiles
/docs/collections/