Skip to content

Instantly share code, notes, and snippets.

@melborne
melborne / import_to_dayone.rb
Last active December 22, 2015 09:09
Dayone text importer
require "date"
class Diary
def self.all
@all ||= []
end
attr_reader :date, :body
def initialize(date, body)
@date = Date.parse(date)
@melborne
melborne / dochood.rb
Last active December 22, 2015 06:49
Dochood module for building document inside a class.
module Dochood
Dochood = Struct.new(:name, :desc, :owner, :kind) do
def self.doc
@doc ||= []
end
def initialize(*args)
super
Dochood.doc << self
end
@melborne
melborne / pikmin.rb
Created August 9, 2013 09:16
Draw Pikmin on Graphviz
require "RMagick"
image_file = 'yellow.png'
img = Magick::ImageList.new(image_file).scale(0.4)
colors = {}
img.rows.times do |y|
img.columns.times do |x|
require "open-uri"
require "rss"
require "json"
#require "yaml"
module Enumerable
def thread_with(delay=0)
mem = []
map do |*item|
sleep delay
class Creature
@@counter = 0
def initialize(name)
@name = name
@@counter += 1
end
def self.count
"You have #{@@counter} creatures."
end
@melborne
melborne / gist:5393407
Created April 16, 2013 04:43
Liquid gumroad tag for Jekyll
# encoding: UTF-8
# A Liquid tag for Jekyll sites that allows embedding Gumroad Overlay link.
# by: Kyo Endo
# Source URL: https://gist.github.com/
#
# Example usage: {% gumroad RjRO Title of Link %}
module Jekyll
class GumroadTag < Liquid::Tag
def initialize(tag_name, text, token)
@melborne
melborne / gist:5393399
Created April 16, 2013 04:41
Liquid table tag for jekyll
# encoding: UTF-8
# A Liquid tag for table.
# by: Kyo Endo
# Source URL: https://gist.github.com/
#
# Example usage:
# {% table border='solid 1px' cellpadding=3px align=center %}
# title aturhor price
# "Programming Ruby" "Charlie Ace" $18.05
@melborne
melborne / graph.ru
Last active December 15, 2015 16:49
Graphviz Layout Sampler with gviz
require "colorable"
cs = Colorable::Colorset[:hsb]
layouts = %w(dot circo fdp sfdp neato twopi osage patchwork)
ns = [*:A..:Z]
nodes shape:'circle', style:'filled'
layouts.each do |layout|
global layout:layout
route ns.first => ns.drop(1)
@melborne
melborne / graph.ru
Created March 27, 2013 14:06
SpaceInvader with Graphviz(Gviz)
require "./invader"
ika_map =
[
[5, 6],
[4..7],
[3..8],
[2, 3, 5, 6, 8, 9],
[2..9],
[4, 7],
@melborne
melborne / graph.ru
Last active December 15, 2015 09:18
Color Tiles with Graphviz
require "colorable"
cs = Colorable::Colorset[:rgb]
global layout:'osage'
nodes shape:'circle', style:'filled', penwidth:5
100.times do |i|
node i.to_id, label:'', width:1.4, fillcolor:"#{cs.next.hex}bb"
end