Skip to content

Instantly share code, notes, and snippets.

View gderosa's full-sized avatar

Guido De Rosa gderosa

View GitHub Profile
@gderosa
gderosa / goldbach.py
Last active April 2, 2025 03:05
Goldbach Conjecture
import pickle
PRIMEFILE = 'primes.pkl'
UPPERLIMIT = 1_000_000
# This script finds Goldbach pairs for odd numbers starting from the last prime found.
# It uses a brute-force method to find the pairs.
# It also serializes the primes found to a file for future use.
# The script will continue from the last prime found in the file.
# It will also handle exceptions and save the state of the primes to a file.
#!/usr/bin/perl -w
# unescape.pl
#
# Copyright (C) 2007 Guido De Rosa <job at guidoderosa dot net>
# Many thanks to Peter Jakobi for contributions and improvements
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
// 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