Skip to content

Instantly share code, notes, and snippets.

View fiorix's full-sized avatar

Alexandre Fiori fiorix

View GitHub Profile
package walkstruct
import (
"fmt"
"reflect"
"unicode"
)
// WalkStruct walks the exported fields of a struct using reflection,
// and calls fn for each field.
#!/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
@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 / freegeoip-httpmux.go
Created March 13, 2016 17:54
freegeoip web server using httpmux
package main
import (
"bytes"
"encoding/csv"
"encoding/json"
"encoding/xml"
"fmt"
"log"
"math/rand"
func RoundUp(v int) int {
return 10 * ((v + 9) / 10)
}
func RoundDown(v int) int {
return 10 * (v / 10)
}
#!/usr/bin/env python
import sys
import time
from getopt import getopt
from PIL import Image
from selenium import webdriver
@fiorix
fiorix / tehcloud.go
Created November 19, 2015 17:13
Slack bot from da hood: tehcloud
package main
import (
"flag"
"log"
"os"
"os/exec"
"strings"
"github.com/nlopes/slack"
@fiorix
fiorix / go-yeah.go
Last active August 29, 2015 14:24 — forked from gleicon/go-yeah.go
package main
import (
"flag"
"io"
"net/http"
"os"
"strings"
"github.com/gorilla/handlers"
@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{}