Skip to content

Instantly share code, notes, and snippets.

View gderosa's full-sized avatar

Guido De Rosa gderosa

View GitHub Profile
// Choose a temperature only at one of the three measurement scales, leave the other two "undefined".
let celsius = undefined
let fahrenheit = undefined
let kelvin = 300
function cToF() {
return celsius * 9/5 + 32
}
function cToK() {
import random
N=8
6**N
dices = [1]*N
n = 1
while dices != [6]*N:
@gderosa
gderosa / colors.rb
Last active December 17, 2015 07:59
require 'digest/sha1'
0.upto(1000).each do |i|
s = i.to_s
digest = Digest::SHA1.hexdigest(s)
fg = digest[0..5]
fg_ = {}
fg_[:r] = fg[0..1]
fg_[:g] = fg[2..3]
@gderosa
gderosa / domount
Last active December 14, 2015 23:08
udev-based automount, "forked" from https://wiki.archlinux.org/index.php/USB_Storage_Devices
#!/bin/bash
# Put this in /etc/udev/rules.d/automount.rules
#
# ACTION=="add", ENV{DEVTYPE}=="partition", RUN+="domount %N"
# All based on:
# https://wiki.archlinux.org/index.php/USB_Storage_Devices
# But:
@gderosa
gderosa / rand.rb
Created March 16, 2012 17:35
Test robustness of random number generator
require 'securerandom'
avg = nil
0.upto(1000) do |k|
n = 0
places = {}
loop do
@gderosa
gderosa / jqueryFileTree_connector.rb
Created January 18, 2012 15:33
jqueryFileTree server-side connector (Sinatra version)
require 'thin'
require 'sinatra'
# by Guido De Rosa, guido.derosa at vemarsas.it, 2012, distributed under the
# same licensing conditions of jqueryFileTree.
# Based on connectors/jqueryFileTree.rb contained in
# labs.abeautifulsite.net/archived/jquery-fileTree/jquery.fileTree-1.01.zip
# An adaptation from CGI to Sinatra.
@gderosa
gderosa / ver_urls.txt
Created October 4, 2011 10:49
Vera notable urls
see also
http://wiki.micasaverde.com/index.php/UI_Simple
http://jsoneditor.net/
http://jsonviewer.stack.hu/
Assuming IP = 192.168.33.155
Get devices etc. (simplified)
@gderosa
gderosa / random_walk.rb
Created July 21, 2011 00:10
Asciiart a pseudo-gaussian histogram as a result of a random-walk stochastic process
WIDTH = 20 # Copyright (C) 2011, Guido De Rosa; License: MIT
histogram = Array.new(1 + WIDTH, 0)
2800.times do
x = WIDTH/2
WIDTH.times { x += (rand <=> 0.5)/2.0 } # random-walk
histogram[x] += 1
end
histogram.each_with_index do |bar_value, i|
printf "%02d ", i; (bar_value.to_f/10).ceil.times {print '|'}; puts
end
@gderosa
gderosa / ruby-alternatives.sh
Created June 17, 2011 12:02
Debian Alternatives for ruby1.9.1
# Adapted from http://kangaroobox.blogspot.com/2009/12/switching-ruby-platforms-on-debian.html
update-alternatives --install /usr/bin/ruby ruby /usr/bin/ruby1.9.1 400 \
--slave /usr/share/man/man1/ruby.1.gz ruby.1.gz \
/usr/share/man/man1/ruby1.9.1.1.gz \
--slave /usr/bin/ri ri /usr/bin/ri1.9.1 \
--slave /usr/bin/irb irb /usr/bin/irb1.9.1
# --slave /usr/bin/gem gem /usr/bin/gem1.9.1
# removed: it's a master alternative now
map{|h| h.rekey{|k| @@chkcols.invert[k]}}