Skip to content

Instantly share code, notes, and snippets.

View ghiden's full-sized avatar

Hidenari Nozaki ghiden

View GitHub Profile
@ghiden
ghiden / schedule.rb
Created March 28, 2012 06:09
specifying which day for "Whenever" gem
#https://github.com/javan/whenever
set :output, "#{path}/logs/cron.log"
every [:sunday, :monday, :tuesday, :wednesday, :thursday], :at => "15:50" do
command "ruby #{path}/something.rb"
end
@ghiden
ghiden / amqp_consumer.rb
Created January 20, 2012 08:16
ruby and node.js message exchange via rabbitmq
require 'amqp'
EventMachine.run do
connection = AMQP.connect(:host => '127.0.0.1', :username => 'guest', :password => 'guest')
puts "Connecting to AMQP broker. Running #{AMQP::VERSION} version of the gem..."
channel = AMQP::Channel.new(connection)
queue = channel.queue("rubyqueue", :auto_delete => true)
exchange = channel.default_exchange
@ghiden
ghiden / chromeThis
Created November 18, 2011 06:38
from Safari, open this page in Chrome
property theURL : ""
tell application "Safari"
set theURL to URL of current tab of window 1
end tell
tell application "Google Chrome"
if not (window 1 exists) then
make new window
end if
@ghiden
ghiden / nodejs_decode_sample.js
Created June 29, 2011 05:11
decode a base64 encoded image file with node.js
var fs = require('fs'),
decode64 = require('base64').decode;
var data = fs.readFileSync('./encode.png', 'base64');
var buffer = new Buffer(data, 'base64');
fs.writeFileSync('./decode.png', decode64(buffer), 'binary')
@ghiden
ghiden / test.js
Created June 22, 2011 04:51
sending a message to specific clients with socket.io
/* just a snippet */
var client_ids = [a, b, c];
for (var cid in client_ids) {
socket.clients[client_ids[cid]].send('hello');
}
@ghiden
ghiden / demo.P
Created October 28, 2010 01:48
A fix for the examples from JPL prolog java binding http://www.swi-prolog.org/packages/jpl/java_api/getting_started.html
Variable X = new Variable("X");
Query q4 =
new Query(
"descendent_of",
new Term[] {X,new Atom("ralf")}
);
java.util.Hashtable solution;
solution = q4.oneSolution();
# a fix for installing nqc onto snow leopard
$ diff -r nqc-3.1.r6 nqc-3.1.r6.fix
diff -r nqc-3.1.r6/rcxlib/RCX_USBTowerPipe_osx.cpp nqc-3.1.r6.fix/rcxlib/RCX_USBTowerPipe_osx.cpp
331c331
< pipe->ReadCompletion(result, (UInt32)arg0);
---
> pipe->ReadCompletion(result, (UInt64)arg0);
Only in nqc-3.1.r6.fix/rcxlib: RCX_USBTowerPipe_osx.cpp~
require 'em-http'
EventMachine.run {
http = EM::HttpRequest.new("http://127.0.0.1:8000/").get
puts 'starting...'
buffer = ""
http.stream do |chunk|
buffer += chunk
while line = buffer.slice!(/.+\r?\n/)
puts line
// based on the java source listed here http://d.hatena.ne.jp/fits/20081126/1227660571
package sample.event
class EsperEvent(val name: String, val point: Int) {
def getName:String = name
def getPoint:Int = point
}
// Original source from here
// http://d.hatena.ne.jp/matsu4512/20090424/1240541319
package {
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageScaleMode;