Skip to content

Instantly share code, notes, and snippets.

View fiorix's full-sized avatar

Alexandre Fiori fiorix

View GitHub Profile
@fiorix
fiorix / groupcache.go
Last active February 6, 2024 10:39
Simple groupcache example
// Simple groupcache example: https://github.com/golang/groupcache
// Running 3 instances:
// go run groupcache.go -addr=:8080 -pool=http://127.0.0.1:8080,http://127.0.0.1:8081,http://127.0.0.1:8082
// go run groupcache.go -addr=:8081 -pool=http://127.0.0.1:8081,http://127.0.0.1:8080,http://127.0.0.1:8082
// go run groupcache.go -addr=:8082 -pool=http://127.0.0.1:8082,http://127.0.0.1:8080,http://127.0.0.1:8081
// Testing:
// curl localhost:8080/color?name=red
package main
import (
@fiorix
fiorix / sse.go
Last active October 19, 2023 08:05
Go and Server Sent Events for HTTP/1.1 and HTTP/2.0
// Go and Server Sent Events for HTTP/1.1 and HTTP/2.0
//go:generate go run $GOROOT/src/crypto/tls/generate_cert.go -host localhost
package main
import (
"fmt"
"io"
"log"
"net/http"
@fiorix
fiorix / cities.py
Created January 22, 2013 07:27
A list of all cities in the world.
#!/usr/bin/env python
# coding: utf-8
#
# The World Gazetteer provides a downloadable file that contains a list
# of all cities, towns, administrative divisions and agglomerations with
# their population, their English name parent country.
#
# Article: http://answers.google.com/answers/threadview/id/774429.html
# Download: http://www.world-gazetteer.com/dataen.zip
@fiorix
fiorix / gist:9664255
Created March 20, 2014 13:55
Go multicast example
package main
import (
"encoding/hex"
"log"
"net"
"time"
)
const (
@fiorix
fiorix / tcp-proxy.py
Created February 21, 2012 21:12
twisted tcp proxy
#!/usr/bin/env python
# coding: utf-8
# http://musta.sh/2012-03-04/twisted-tcp-proxy.html
import sys
from twisted.internet import defer
from twisted.internet import protocol
from twisted.internet import reactor
from twisted.python import log
@fiorix
fiorix / proxy.go
Last active June 20, 2022 09:22
proxy that can handle/modify html responses
package main
import (
"io"
"net/http"
"strings"
)
func main() {
p := &proxy{}
#!/bin/bash
FRAMES_DIR=frames.$$
trap "rm -rf ${FRAMES_DIR}" EXIT
FPS=10
WIDTH=480
FONT_COLOR=white
INPUT="$1"
@fiorix
fiorix / pct-diff-calc.py
Created March 10, 2017 00:48
Percentage Difference Calculator
#!/usr/bin/env python
# Implementation of http://www.calculatorsoup.com/calculators/algebra/percent-difference-calculator.php
v1=5067
v2=5733
def diff(v1, v2):
f1, f2 = float(v1), float(v2)
v = 1 - ((f1 - f2) / ((f1 + f2) / 2) * 100) - 1
return v
#!/usr/bin/env python
# coding: utf-8
# How Twisted's inlineCallbacks work?
# If you use it but don't know exactly what it does,
# and didn't understand the code shipped with Twisted,
# keep reading.
import types, functools
from twisted.python import failure
from twisted.web.client import getPage
package walkstruct
import (
"fmt"
"reflect"
"unicode"
)
// WalkStruct walks the exported fields of a struct using reflection,
// and calls fn for each field.