A new project to learn the Crystal Programming Language

I’ve started a new side project named Crystal Koans, it’s a simple series of exercises organized as a big unit test suite. The “koans” are heavily inspired by similar projects for other languages, but I didn’t found anything similar for Crystal. The project has been included in the awesome collection under the official Learning Resource for the language. I’ll try to maintain and evolve it in the spare time, I hope you’ll find it useful, and any form of contribution is welcome....

November 20, 2020 · Andrea Manzini

playing with Crystal Programming Language

I’ve started experimenting with the Crystal Programming Language. It’s a nice and clean language with syntax similar to Ruby, but compiled to fast native code, and a lot of clever ideas, like union types and seamless C integration The project is still in early stages, but it’s promising. Just to see how easy, I ported a small python library to Crystal, you can find it on https://github.com/ilmanzo/spark. I hope to find the time to improve on it!...

October 11, 2016 · Andrea Manzini

semplice rate limit in Sinatra

Giocando con Sinatra ho avuto l’esigenza di servire una determinata pagina solo con un certa frequenza (tecnicamente un rate-limit); la cosa si puo’ fare installando il middleware Rack:Throttle ma non volevo aggiungere un’altra gemma alle dipendenze… In questo esempio se al server arriva piu’ di una richiesta in un intervallo di cinque secondi, rispondiamo a tono… 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 ?...

December 21, 2012 · Andrea Manzini

gestire i led delle schede PC Engines ALIX in Ruby

Natale si avvicina: mentre smanettavo su queste ottime PC Engines ALIX su cui ho installato una Debian modificata, ho scritto una comoda interfaccia per accendere/spegnere e far lampeggiare i led alla velocita’ desiderata… 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') } File.open(@ledsyspath+'delay_off','w') do |f| f.write(millisec.to_s) end File.open(@ledsyspath+'delay_on','w') do |f| f....

November 9, 2012 · Andrea Manzini