Skip to content

Instantly share code, notes, and snippets.

@nanki
nanki / ffi-ruby.rb
Created November 3, 2011 13:59
FFI bridge to libruby.
require 'ffi'
module FFI::Ruby
class Value
class << self
extend ::FFI::Library
ffi_lib 'ruby'
attach_function :rb_obj_id, [:pointer], :pointer
attach_function :rb_num2long, [:pointer], :long
@nanki
nanki / olm.rb
Created October 21, 2011 18:17
One liner music player for Ruby. http://hitode909.appspot.com/one-liner-music/
require 'rubygems'
require 'ffi-portaudio'
def safe
r = nil
Thread.new {
$SAFE = 4
r = yield
}.join
r
@nanki
nanki / ascii_eq.rb
Created September 20, 2011 16:33
ASCII equalizer.
require 'ffi'
module FFI::PortAudio
module API
extend FFI::Library
ffi_lib 'portaudio'
Int16 = 0x8
FramesPerBufferUnspecified = 0
@nanki
nanki / grepedit.vim
Created September 19, 2011 19:51
vim syntax file for grepedit.
function! s:syntax(name, ext)
let l:separator = "^# ============================================================ "
let l:ext = empty(a:ext) ? "" : "¥¥.".a:ext
let l:cmd = "syntax region GEBlock".a:name
¥." matchgroup=FileLine "
¥."start=/".l:separator.".*¥¥v".l:ext."$/ "
¥."end=/¥¥(".l:separator.".*$¥¥)¥¥@=¥¥|¥¥%$/ "
¥."keepend transparent contains=FileLine"
let l:cmd .= empty(a:name) ? "" : ",@".a:name
@nanki
nanki / a.rb
Created September 11, 2011 08:57
1.8.7/1.9.2
# $ echo 'class B;end' > b.rb
b = Thread.new { p autoload(:B, './b') }
sleep 0.00002
b.kill
B
@nanki
nanki / console.c.diff
Created September 8, 2011 20:11
io-console for jruby.
--- console.c.orig 2011-09-09 04:59:09.000000000 +0900
+++ console.c 2011-09-09 05:08:30.000000000 +0900
@@ -4,6 +4,9 @@
*/
#include "ruby.h"
#include "rubyio.h"
+
+#include <errno.h>
+
#ifndef HAVE_RB_IO_T
@nanki
nanki / sirb.rb
Created September 3, 2011 07:37
Super-interactive ruby console.
#!/usr/bin/env ruby
# -*- coding: UTF-8 -*-;
require 'io/console'
require 'ansi'
class Textbox
def initialize(input=$stdin)
@input = input
end
@nanki
nanki / ff.rb
Created August 27, 2011 07:02
file filter: $ ff -@bin -_test.rb controller ...
#!/usr/bin/env ruby
require 'open3'
EXCLUDE_EXTENTSONS = %w(psd gif jpg png DS_Store tmp JPG PNG swp swf o bundle dylib so)
EXCLUDE_FROM_CURRENT = %w(estraier tmp log coverage build)
subdirs = Dir.glob("*")
subdirs -= EXCLUDE_FROM_CURRENT
def process_args(argv, _subdirs, _patterns)
puts (1..100).map{|i|[[i, :Fizz], [:Buzz, :FizzBuzz]][(1 - i**4) % 5][(1 - i**2) % 3]}
@nanki
nanki / edit.rb
Created March 28, 2011 13:15
Edit ruby string by the editor.
# editor.rb
#
# $ irb -reditor
# > Editor.edit("abc") # Edit "abc" with the external editor.
# => "abc has changed"
#
# Author: @nanki / nanki at dotswitch dot net
require 'tempfile'