Skip to content

Instantly share code, notes, and snippets.

View costajob's full-sized avatar

Michele Costa costajob

View GitHub Profile
$vertx.create_http_server().request_handler() do |req|
req.response()
.put_header(content-type, "text/plain")
.end("Hello World")
end.listen(9292)
@costajob
costajob / decorator.py
Last active March 29, 2018 09:43
Playing with python decorators
from datetime import datetime
from time import sleep
from sys import argv
def measure(func):
def decorator(n):
start = datetime.now()
res = func(n)
end = datetime.now()
@costajob
costajob / Wget recursive command
Last active February 16, 2017 09:13
wget command to fetch password protected site recursively
wget --load-cookies cookies.txt --recursive \
--no-clobber \
--page-requisites \
--html-extension \
--convert-links \
--domains <your_domain> \
--no-parent <specific URL path>
require "http/server"
class Cluster
def initialize(@n : Int32, @port : Int32, @io : IO = STDOUT)
@workers = Array(Process).new
@pid = Process.pid
end
def call
head
@costajob
costajob / haproxy.cfg
Last active August 4, 2016 15:32
Nginx and haproxy configuration for balancing a bunch of HTTP servers running on different ports
global
maxconn 4096
pidfile /tmp/haproxy-queue.pid
defaults
mode http
timeout connect 300000
timeout client 300000
timeout server 300000
maxconn 2000
@costajob
costajob / http_cluster.cr
Last active November 24, 2022 09:09
Barebones HTTP server cluster in Crystal lang
require "http/server"
module HTTPCluster
struct Worker
def initialize(@pid : Int32, @master : Int32)
end
def call(port)
yield(port)
end
@costajob
costajob / fact.cr
Last active September 20, 2022 21:15
Factorial implementation using Big numbers in Ruby, GO and Crystal
require "big_int"
def fact(n)
return 1 if n == 0
n * fact(n - 1)
end
n = BigInt.new(ARGV[0])
puts fact(n)
def stores_for_user
@stores = OsaUser.find_all_by_user(params[:user]).
map{|x| [x.store_code, x.store_description]}.uniq unless params[:user].blank?
respond_to do |format|
format.json { render :json => @stores}
end
end