Skip to content

Instantly share code, notes, and snippets.

@nanki
nanki / dot.rb
Created March 17, 2013 15:03
draw circle with Unicode Braille Patterns.
# -*- coding: UTF-8 -*-;
def dot(index)
index = index & 7 | (index & 112) >> 1 | (index & 8) << 3 | index & 128
case index
when 0
" "
else
[0x2800 + index].pack('U*')
end
@nanki
nanki / file1.txt
Created March 7, 2013 17:43
PlantUMLを使ってシーケンス図を描く ref: http://qiita.com/items/2d4da7ccb2d74732c737
message
--------------------->
,---!.
|eat|_\
@nanki
nanki / pivot.rb
Created September 27, 2012 06:53
CUI pivot table.
#!/usr/bin/env ruby
# -*- coding: UTF-8 -*-;
gem 'text_layout'
require 'optparse'
require 'text_layout'
require 'set'
opts = OptionParser.new <<EOS
@nanki
nanki / gml.rb
Created August 17, 2012 09:52
generate .gml from space-separated-values.
#!/usr/bin/env ruby
i = 0
hash = {}
edges = ''
ARGF.each do |line|
id1, id2s = line.strip.split /\s/
id2s.split(",").each do |id2|
hash[id1] ||= i += 1
@nanki
nanki / dumptab.applescript
Created June 30, 2012 08:42
dump the contents of the current tab in Terminal.app
#!/usr/bin/osascript
tell application "Terminal"
contents of selected tab of front window
end tell
diff: 2100
*path*: 120
.: 75
--help: 19
-p: 15
-w: 14
--no-color: 3
--: 14
*path*: 10
--no-color: 13
require 'ffi'
module FFI::MRuby
extend ::FFI::Library
ffi_lib 'ritevm'
enum :mrb_vtype, [
:FALSE, :FREE, :TRUE, :FIXNUM,
:SYMBOL, :UNDEF, :FLOAT, :OBJECT,
require 'ffi'
module Union
extend ::FFI::Library
ffi_lib 'union'
class U < FFI::Union
layout(
:d, :double,
:i, :int
#include <stdio.h>
typedef union {
double d;
int i;
} union_t;
void dump_union(union_t u) {
unsigned char *c = (unsigned char *)&u;
@nanki
nanki / queuetest.rb
Created April 28, 2012 16:28
seems slow on 1.9.3
#!/usr/bin/env ruby
# -*- coding: UTF-8 -*-;
require 'thread'
require 'time'
class App
Bus = Struct.new :draw, :visualize
Info = Struct.new :title, :text