Skip to content

Instantly share code, notes, and snippets.

@clicube
clicube / roomba.pde
Created October 31, 2012 08:15
Roomba for Processing
class Roomba
{
float x;
float y;
float rad;
float r;
static final color c_lgray = #c0c0d0;
static final color c_gray = #acacbc;
static final color c_dgray = #909090;
static final color c_lblack = #303030;
@clicube
clicube / networksetup.rb
Created January 8, 2013 03:58
Access networksetup info on OSX from Ruby
# coding: utf-8
module NetworkSetup
def self.network_services
result = `networksetup -listallnetworkservices`.each_line.map{|l|l.strip}
result.shift
return result
end
@clicube
clicube / 0_shuron_bot.rb
Last active December 10, 2015 19:29
shuron_bot (for mac)
# coding: utf-8
require 'mini_exiftool'
require 'twitter'
require_relative 'simplestore'
# https://gist.github.com/4482749
require_relative 'networksetup'
# https://gist.github.com/4481049
store = SimpleStore.new(File.dirname(__FILE__)+"/store.yaml")
@clicube
clicube / simplestore.rb
Last active December 10, 2015 19:39
SimpleStore is initialized with file path of YAML file, can be used like Hash, and can be saved to the file.
# coding: utf-8
require 'yaml'
class SimpleStore < BasicObject
attr_reader :file
def initialize(file)
@file = file
if(::File::exist?(file))
@clicube
clicube / mpqueue.rb
Created January 15, 2013 07:54
queue for multi processing
# coding: utf-8
class MPQueue
def initialize
@wcout,@wcin = IO.pipe # lock for write
@rcout,@rcin = IO.pipe # lock for read
@lout,@lin = IO.pipe
@dout,@din = IO.pipe
@clicube
clicube / argsvalidator.rb
Last active December 11, 2015 04:19
validate arguments of instance method
module ArgsValidator
def self.validate_args name, args, rules, klass
([args.length,rules.length].min).times do |i|
arg = args[i]
rule = rules[i]
next if rule == :any
rule = rule.class unless rule.class <= Class
unless arg.class <= rule
th = %w[st nd rd][i%10] || 'th'
@clicube
clicube / namedpipe.rb
Last active December 11, 2015 17:29
IO.named_pipe(path, create=true) path: path of named pipe (fifo) create: create pipe if true
class IO
def self.named_pipe(path, create=true)
if !File.exist?(path)&& create
system "mkfifo #{path}"
end
raise IOError.new("it is not named pipe") if File.ftype(path) != "fifo"
pout = File.open(path, "r+")
pin = File.open(path, "w+")
return pout, pin

debian(i386)@さくらVPS(1G) 初期設定メモ

ネームサーバの設定

valuedomainの設定欄に以下を記入

mx @ 10
a * <IP address>

インストール時

@clicube
clicube / humanlike_mechanize.rb
Created February 8, 2013 17:13
HumanlikeMechanize waits before each get/post
require 'mechanize'
class HumanlikeMechanize < Mechanize
def initialize min,max
raise ArgumentError.new("min > max") if min > max
raise ArgumentError.new("min < 0") if min < 0
raise ArgumentError.new("max < 0") if max < 0
@sleep_min = min
@sleep_max = max
@clicube
clicube / ipv4header.rb
Created February 18, 2013 17:02
Read TCP, UDP, IP header by Ruby
# coding: utf-8
require_relative 'protocol'
# TODO: チェックサムを確認する
class IPv4Header
attr_reader :version,:header_length,:packet_length,:identification,:frag_dont,:frag_more,:frag_offset,:ttl,:protocol,:checksum,:sndr_addr,:dest_addr,
:data_length
def initialize(packet,offset=0)