Skip to content

Instantly share code, notes, and snippets.

@wstucco
wstucco / state_machine.pde
Created February 28, 2014 17:54
Processing.org state machine
interface State {
public State nextState();
}
class IdleState implements State {
public State nextState() {
return new ScanState();
}
}
@wstucco
wstucco / elixir_brainfuck_interpreter_part_2.exs
Last active August 29, 2015 14:09
elixir_brainfuck_interpreter_part_2.exs
defmodule Brainfuck do
# opcodes
@op_vinc "+" # increment value at memory address
@op_vdec "-" # decrement value at memory address
@op_pinc ">" # increment memory address
@op_pdec "<" # decrement memory address
@op_putc "." # output byte at memory address
@op_getc "," # input byte into memory address
@op_lbeg "[" # loop begin
@wstucco
wstucco / app.json
Last active August 29, 2015 14:10
OpenFin
{
"env": "2.0.7.0",
"startup_app": {
"name": "Hello Open Fin",
"url": "http:/localhost:5000/index.html",
--> "uuid": "OpenFinHelloWorld",
.
.
.
}
/*
* Copyright (C) 2012, Tino Didriksen Consult
* Developed by Tino Didriksen <tino@didriksen.cc>
* Modified by Massimo Ronca
*
* This file is part of Benchmarks
*
* Benchmarks is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or

Keybase proof

I hereby claim:

  • I am wstucco on github.
  • I am massimo (https://keybase.io/massimo) on keybase.
  • I have a public key whose fingerprint is 4538 9292 4496 E67A 6CE2 BF39 5D2C 6772 9E02 C529

To claim this, I am signing this object:

@wstucco
wstucco / build.sh
Last active October 12, 2015 00:55
Writing Ruby Extensions in go
go build -buildmode=c-shared -o hello.so hello.go
# if no error is returned you can check that the shared library is exporting
# the right symbols by executing
# $ nm -gU ./hello.so | grep hello
# 0000000000002050 T __cgoexp_d4a435ec6890_hello_world
# 0000000000001ae0 T _hello_world <--- ALL SYSTEMS ARE GO
@wstucco
wstucco / require_valid_argument_1.php
Last active December 15, 2015 02:39
three different versions of a function handling parameters validation
<?php
// Takes the parameter value and validate it against a
// list of known validators and throws an exception if it doesn't
//
// params:
// mixed $value
// string $validator
//
@wstucco
wstucco / git_rewrite_email
Last active December 17, 2015 08:28
change committer email and rewrite history
git filter-branch --commit-filter '
if [ "$GIT_AUTHOR_EMAIL" = "<email>" ];
then
GIT_COMMITTER_EMAIL="<new-email>";
GIT_AUTHOR_EMAIL="<new-email>";
git commit-tree "$@";
else
git commit-tree "$@";
fi' HEAD
@wstucco
wstucco / example-1.1.go
Last active December 27, 2015 01:59
I tried Go and I liked it
package main
import (
"fmt"
"net/http"
)
func main() {
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
@wstucco
wstucco / find_similar_ip.ex
Last active July 21, 2017 09:51
most similar ip Elixir
{:ok, ips} = :inet.getif()
ips
|> Enum.map(fn {ip, _broadaddr, _mask} -> ip |> Tuple.to_list |> Enum.map_join(".", &to_string/1) end)
|> Enum.map(fn ip -> {ip, String.jaro_distance(ip, "192.168.99.100")} end)
|> Enum.sort(fn {_, score1}, {_, score2} -> score1 > score2 end)
|> List.first
|> elem(0)