Skip to content

Instantly share code, notes, and snippets.

View ghiden's full-sized avatar

Hidenari Nozaki ghiden

View GitHub Profile
# inside rails controller, to check http headers
request.headers.each do |k,v|
logger.debug "#{k} -> #{v}"
end
@ghiden
ghiden / gist:441735
Created June 17, 2010 05:56
flash[:notice] and flash[:error]
<p id="flash" class="<%= flash.keys.first.to_s %>"><%= flash.values.first %></p>
# using Paginator with MongoMapper
# index action in a controller
def index
@pager = Paginator.new(User.count, 20) do |offset, per_page|
User.all(:offset => offset, :limit => per_page, :order => "created_at DESC")
end
@users = @pager.page(params[:page])
respond_to do |format|
format.html # index.html.erb
$ git diff
diff --git a/init.rb b/init.rb
index f0a5316..29f7a2d 100644
--- a/init.rb
+++ b/init.rb
@@ -73,6 +73,14 @@ Redmine::WikiFormatting::Macros.register do
:id => attach.id,
:filename => attach.filename
+ thumb_filename = "#{tw}_#{th}_#{attach.disk_filename}"
// 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;
// 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
}
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
# 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~
@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();
@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');
}