Skip to content

Instantly share code, notes, and snippets.

View glurp's full-sized avatar

Abby Archer glurp

View GitHub Profile
@glurp
glurp / deepclone.rb
Created August 8, 2017 20:51
Benchmark ruby deep_clone
require 'benchmark'
class Object
def deep_clone1() Marshal.load(Marshal.dump(self)) end
def deep_clone2() self.clone end
def deep_clone3() eval(self.inspect) end
def ewb(o) self.each_with_object(o) { |k,oo| yield(k,oo) } end
end
class Numeric
def deep_clone2() self+0 end
@glurp
glurp / glurp_utils.rb
Created July 20, 2017 17:41
utils for ruby dev
################################################################################
# utils.rb
################################################################################
#
# ssh : ssh_exec(...)
# scp : scp_get_file(...)
# scp_get_dir(...)
# scp_put_file(...)
# scp_get_dir(...)
#
@glurp
glurp / gem_download_tracking.rb
Last active June 2, 2017 11:37
track downloading of a gem from https://rubygems.org
require 'open-uri'
require 'nokogiri'
def getCount(name)
url="https://rubygems.org/gems/#{name}"
Nokogiri::HTML(open(url)).css("span.gem__downloads").last.content.gsub(/[\D]+/,'').to_i
end
framework="Ruiby"
@glurp
glurp / radix_tree.rb
Last active April 19, 2017 18:40
implemnt radix tree in pure ruby
w=%w{acquittement acquittements acquittent acquitter acquittera acquitterai acquitteraient acquitterais acquitterait acquitteras acquitterent acquitterez acquitteriez acquitterions acquitterons acquitteront acquittes acquittez acquittiez acquittions acquittons }
w=%w{romane romanus romulus rubens ruber rubuicon rubicundus}
class String
def common(other)
return('') if size==0 || other.size==0
scan(/./).zip(other.scan(/./)).to_a.each_with_object([]) {|(a,b),l| if a==b then l<<a else break(l) end }.join("")
end
end
@glurp
glurp / lceb.rb
Last active May 16, 2016 18:46
"Le Compte est bon" solver in ruby
# find 101 with [2, 4, 5, 7, 10, 50] :
# 4 add 50 => 54 | 54 mult 2 => 108 | 108 moin 7 => 101
$op=%i{div mult add moin}
# elementary calculation, with "Le compte est bon" specific rules
def calc(n1,op,n2)
case op
when :add then n1+n2
when :moin
@glurp
glurp / cotations.rb
Last active December 9, 2015 14:38
show cotations, with curves
##############################################################
# bourse.rb
##############################################################
require 'json'
require 'httpclient'
require 'yahoo-finance'
unless Dir.exists?("dsl-gtk")
require 'Ruiby'
else
require_relative 'dsl-gtk/lib/Ruiby.rb'
@glurp
glurp / dsort.cr
Created July 22, 2015 18:48
final comparaison between libc.qsort, qsort and dsort in crystal
################################ Crystall scripts
def chrono(text)
s=Time.now
yield
e=Time.now
d=(e.to_f-s.to_f)*1000
if d>1
puts "#{text} : #{d} ms"
else
@glurp
glurp / sort.rb
Created July 22, 2015 13:18
functional sort algotithmes in ruby
def chrono(text=nil,div=1)
date_start=Time.now.to_f
yield
date_end=Time.now.to_f
duree= (date_end - date_start)*1000
duree/=div if div>1
sduree= case duree
when 0..1 then (duree*1000).to_s + " micro s."
when 1..3000 then duree.to_s + " ms"
when 3000..10000 then (duree/1000).to_s + " sec"
@glurp
glurp / sort.cr
Last active August 29, 2015 14:25
functional sort algorithmes comparaison in crystal
################################ Crystal scripts
def chrono(text)
s=Time.now
yield
e=Time.now
d=(e.to_f-s.to_f)*1000
if d>1
puts "#{text} : #{d} ms"
else
@glurp
glurp / slides.md
Created July 8, 2015 16:47
test slides

No Software

No Apps, No Servers

Only You

Your Browser

And an idea worth sharing