Skip to content

Instantly share code, notes, and snippets.

@ilmanzo
ilmanzo / ClassBackgroundJob.rb
Created November 5, 2012 13:22
a class to execute some command in background
class BackgroundJob
def initialize(cmd)
@pid = fork do
# this code is run in the child process
# you can do anything here, like changing current directory or reopening STDOUT
exec cmd
end
end
@ilmanzo
ilmanzo / AlixLed.rb
Created November 9, 2012 09:35
Led sulle PC Engines ALIX
class Led
#numero da 1 a 3
def initialize(ledno)
ledno++ # passo 0 ma comando 1
ledno=1 if ledno<1
ledno=3 if ledno>3
@ledsyspath="/sys/devices/platform/leds_alix2/leds/alix:#{ledno}/"
end
def blink(millisec)
File.open(@ledsyspath+'trigger','w') { |f| f.write('timer') }
SECONDS_BETWEEN_REQUEST=5
enable :sessions
def ratelimit?
now=Time.new.to_i
session['lastrequest']||=0 #inizializza se non presente
result=(now-session['lastrequest'])<SECONDS_BETWEEN_REQUEST #passati dall'ultima richiesta ?
session['lastrequest']=now # aggiorna
return result
@ilmanzo
ilmanzo / gist:fcba47b0b79d4cb1e1768d688a6992a8
Last active January 30, 2018 12:39
prova testo due colonne
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8"></meta>
<meta
name="viewport"
content="width=device-width, initial-scale=1, shrink-to-fit=no"
></meta>
; setup
;
; sudo apt-get install cmatrix nasm ; nasm -f elf64 -o matrix.o matrix.asm ; ld -o matrix matrix.o; ./matrix
SECTION .text
global _start
_start:
mov rdx, environment ; address of environment variables
@ilmanzo
ilmanzo / spinner.py
Last active October 27, 2019 16:44
classe "spinner" per AstroPi SenseHat
from sense_hat import SenseHat
import time
import math
sensehat = SenseHat()
sensehat.low_light = True
class Spinner():
def __init__(self,sensehat):
@ilmanzo
ilmanzo / main.py
Last active December 19, 2019 16:45
scheletro per AstroPi "life in space" con display spinner integrato
import ephem
from math import radians, degrees, cos, sin, asin, sqrt
from sense_hat import SenseHat
import time
import math
import os
import datetime
from time import sleep,strftime
import logging
import logzero
module main
struct List {
head &Node
name string
}
struct Node {
mut: data int
next &Node
@ilmanzo
ilmanzo / ssh_client_example.go
Last active May 17, 2024 23:16
example for ssh client in Go with username and password authentication
package main
import (
"bytes"
"fmt"
"log"
"golang.org/x/crypto/ssh"
)
func main() {
@ilmanzo
ilmanzo / aoc_2021_day1.nim
Last active December 1, 2021 14:31
Advent of Code 2021: day1 solution in Nim
import std/strutils
import std/sequtils
proc count_increases(items : seq[int]) : int =
for i in 1 .. items.high:
if items[i] > items[i - 1]:
inc result
proc get_sums(items: seq[int]) : seq[int] =
for i in countup(2,items.len-1):