Skip to content

Instantly share code, notes, and snippets.

View glurp's full-sized avatar

Abby Archer glurp

View GitHub Profile
static public Object to_jsonnable(Object o) {
if (o instanceof List) {
List lo = (List)o;
ArrayList nlo = new ArrayList();
for (Object a : lo) nlo.add(to_jsonnable(a)) ;
return(nlo);
} else if (o instanceof Map) {
Map mo = (Map)o;
LinkedHashMap<Object, Object> nmo =
new LinkedHashMap<Object, Object>();
@glurp
glurp / gs_gtk2_util.rb
Created July 21, 2011 16:52
systray api for green_shoes
require 'gtk2'
############################ SysTray ###############################
module Gtk
class SysTray < StatusIcon
def initialize(window,title="title?",config)
@glurp
glurp / gs_thread_util.rb
Created July 21, 2011 17:53
thread asynchronous invoker for shoes application
require 'thread'
class Object
def invoke_in_shoes_mainloop(&blk)
return unless defined?($__shoes_app__)
return unless Shoes::App===$__shoes_app__
$__shoes_app__.get_queue().push( blk )
end
end
@glurp
glurp / serbench.rb
Created August 12, 2011 15:08
Serialisation benchmark
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
require 'yajl'
require 'benchmark'
require 'pp'
require 'zlib'
def fract(n) n==0? 'eeee' : {"l"+n.to_s => fract(n-1) , :i=> (0..n).to_a, "r"+n.to_s => fract(n-1) } ; end
class String ; def zip() Zlib::Deflate.deflate(self,3) end end
@glurp
glurp / pm.rb
Created August 12, 2011 15:24
Paralelle map
pm=ParalleleMap.new(
:nbThread => 5,
:generator => proc { |res|
rfind("/" , ".rb" ) { |file| res << file ; }
},
:mapper => proc { |out,in_file_name|
selectLine(out,query,in_file_name)
},
:reducer =>proc { |rr| reduce(rr) },
:debug => (debug!=nil)
@glurp
glurp / p2p.rb
Created August 19, 2011 21:48
micro p2P
################################################################################
# S h o e s P 2 P
################################################################################
# 2 types of member:
# serveur : give only adresses of all member which had connect to him
# client : take list of member from one or several serveur,
# echange files with others known clients
# clients are server too
#
# so server(s) are necessary only at startup of a client.
@glurp
glurp / s2s.rb
Created August 21, 2011 23:11
HMI of S2S
require 'green_shoes'
require './p2p.rb'
######################" Patch ChipMunk : destroy a shape....
#---------- append shap to attribute
ChipMunk # load file (ext are autoloaded by greeen shoes)
module ChipMunk
def spy
@glurp
glurp / s2s.rb
Created August 23, 2011 14:26
statusbar cant be drow in black color
require 'green_shoes'
#require './p2p.rb'
######################" Patch ChipMunk : destroy a shape....
#---------- append shap to attribute
ChipMunk # load file (ext are autoloaded by greeen shoes)
module ChipMunk
def spy
@glurp
glurp / tree.rb
Created September 10, 2011 13:39
Green shoes fractal, (from rosettacode.org)
require 'green_shoes'
Shoes.app(:title => "Fractal Tree", :width => 600, :height => 600) do
background "#000".."#777"
stroke "#000"
@deg_to_rad = Math::PI / 180.0
C=%w{AA0 EE0 FF0 EE0 EE8 EF8 8F8 7F7 0F0 5BB 0FF FAA}
def drawTree(x1, y1, angle, depth)
return if depth <= rand(2)
s=3+rand(4)
x2 = x1 + (Math.cos(angle * @deg_to_rad) * depth * s).to_i
@glurp
glurp / space navigation.rb
Created September 23, 2011 22:10
ANG game.tb
#!/usr/bin/ruby19
###########################################################################
# ANG.RB : planetoide game
#--------------------------------------------------------------------------
# install ruby
# install Gosu > gem install gosu
# download this > git clone http://github.com/rdaubarede/ang.git
# run > cd ang ; ruby main.rb
# do your own version :
# > loop { edit/main.rb ; ruby main.rb }