Skip to content

Instantly share code, notes, and snippets.

View VictorTaelin's full-sized avatar

Victor Taelin VictorTaelin

View GitHub Profile
// (b:Nat), Vector3 -> BoundedNat (b*b)
function packUnitVector(sqrtBase, v){
var f = Math.sqrt(8*v[2]+8);
var u = (v[0]/f+0.5)||0.5;
var v = (v[1]/f+0.5)||1;
return Math.round(u*sqrtBase) + Math.round(v*sqrtBase)*sqrtBase;
};
// (b:Nat), BoundedNat (b*b) -> Vector3
function unpackUnitVector(sqrtBase, e){
import Data.List
import Data.Char
-- Um amigo meu perguntou como eu resolveria o seguinte problema
-- em Haskell, na vida real: http://i.imgur.com/Sno61vt.jpg
-- Leia ele antes de continuar! Minha resposta é a seguinte:
main = do
inicio <- getTime -- seja `inicio` um tempo lido do console
fim <- getTime -- seja `fim` outro tempo lido do console
@VictorTaelin
VictorTaelin / lrs_tests.txt
Last active September 16, 2016 21:40
Linkable Ring Signatures work :)
:: Generating ring with 16 members...
:: Generated PUB/PVT key pairs:
MEMBER 0: 3a514119648cf6ed9f0cc6c955de0ad05916bb407c74a07c130416dfef83ee0066f7118e68e3a648bf09d07fab7c0ba66c75cc3cad9122e590baa1c26d7012a4b001e4f48f4154a61acf7201f0c307359bccfa71e03e3b9d49bc9b3bc5d2fccd/21fcf5df638181233aa85e20f164d2fe2969458e972036188b38f8988f36e2ca7fa7439e558aed9cd2d19528607a45a7a1e0fda8e340926c917fd821860bb58715fe4683106e23f2c2954df70ad45d0cfdca2406f024238270b265c1bd1ba6f9
MEMBER 1: 8a651ebc654dffb5d7ae5d40e00a03f15bd90f299680a767ed1f600d004927dc859059782c8c884400cffeff4bd78e6dac338e48855c4e769ef2802d0eed95f550cbc4c6431b56c53d512b150db7fff77443109d70ef11007ade68848c89bc00/df92eea88372ca57e1056327bb5e3409032b0cba09329ffcef1c5fd53abf6ab9ca8e492e9ba7d09cc271904da955357b2ab74a9614994b09586de4a3af0f11b82506516bff0c3a191f378bfbffe123eabdee06a7c1bf2f9c5703efc2e3a7e9b
MEMBER 2: 296cf951174b2a5984b53ceada5e5999436aafca466f1d11178087d73d56176aa51a13ab2493e958faf1d75ed8a77e45ba3860d65b1e8db8cf12f589b27d6fc398973566834e0ba857aa7ed6
@VictorTaelin
VictorTaelin / gist:41a055de78c80511408558f4ca43ca01
Last active October 14, 2016 15:22
most of Data.List's functions without recursion
-- Church encoded constructors
cons = (Data.constructor 0 (List _))
nil = (Data.constructor 1 (List _))
-- Returns the first element of a church-encoded list
head = (cons?,nil?)
cons? h t = h
nil? = nil
-- Returns the tail of a church-encoded list
@VictorTaelin
VictorTaelin / untyped_float_jit.js
Last active October 29, 2016 19:39
Untyped lambda calculus with floating point arithmetic primitives and JIT compilation to/from JS
module.exports = (function(){
// Constructors
var VAR = 1, LAM = 2, APP = 3, NUM = 4, OPC = 5;
function Lam(bod){ return {type:LAM, bod:bod}; };
function App(fun,arg){ return {type:APP, fun:fun, arg:arg}; };
function Var(index){ return {type:VAR, index:index}; };
function Num(num){ return {type:NUM, value:num}; };
function Opc(op,a,b){ return {type:OPC, op:op, a:a, b:b}; };
module.exports = (function(){
function Book(baseCurrency, token){
var book = {};
book.offers = {};
book.offers[baseCurrency] = [];
book.offers[token] = [];
book.pair = [baseCurrency, token];
return book;
};
function offer(offer, book, debug){
{"r":16801,"rule":[1,2,0,1,0,0,2,1,2],"len":63768}
{"r":8481,"rule":[0,1,0,2,2,1,2,0,1],"len":63768}
{"r":11871,"rule":[0,0,2,1,2,0,1,2,1],"len":63768}
{"r":10401,"rule":[0,2,0,1,2,0,2,1,1],"len":63768}
{"r":14881,"rule":[1,1,0,2,0,1,2,0,2],"len":63768}
{"r":8703,"rule":[0,0,1,1,2,2,2,0,1],"len":63768}
{"r":5231,"rule":[2,0,2,1,1,0,1,2,0],"len":63768}
{"r":14881,"rule":[1,1,0,2,0,1,2,0,2],"len":63768}
{"r":8481,"rule":[0,1,0,2,2,1,2,0,1],"len":63768}
@VictorTaelin
VictorTaelin / mydreamdb.md
Last active December 16, 2021 19:13
MyDreamDB

There is nothing more annoying than databases. Absolutely all DBs nowadays are based on some kind of pre-determined data structure (tables, documents, key/val stores, whatever) plus some methods to mutate data on them. They're the functional programmer's worst nightmare and one of the few "imperative" things that still impregnate Haskell programs. I wonder if there isn't, on this human world, a single functional-oriented DB.

I'm thinking of an app-centric, append-only-log database. That is, rather than having tables or documents with operations that mutate the database state - like all DBs nowadays do, and which is completely non-functional - it would merely store an immutable history of transactions. You would then derive the app state from a reducer. Let me explain with an example. Suppose we're programming a collective TODO-list application. In order to create a DB, all you need is the specification of your app and a data path:

Local database

import MyDreamDB
function hash(bits, len){
var tt = [1,2,0,0,0,1,1,2,2];
var st = [];
for (var i=0; i<128; ++i)
st.push(i%3);
var os = [];
for (var k=0, l=st.length, il=bits.length; k<il+len; ++k){
for (var j=0; j<32; ++j){
if (k < il)
st[0] = bits[k];
#include <stdio.h>
void hash(int* bits, int bitsLen, int* out, int outLen){
const int tt[9] = {1,2,0,0,0,1,1,2,2};
int st[128], i, k, j, x, y, a, b, o = 0;
for (int i=0; i<128; ++i)
st[i] = i%3;
for (k=0; k < bitsLen + outLen; ++k){
for (j=0; j<32; ++j){
if (k < bitsLen)