Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View marcoonroad's full-sized avatar
🦋
the Future() has been CANCELLED and we .Restart() the DEAD Event[] from the past

Marco Aurélio da Silva marcoonroad

🦋
the Future() has been CANCELLED and we .Restart() the DEAD Event[] from the past
View GitHub Profile
@marcoonroad
marcoonroad / hashcrypt.js
Created November 1, 2018 18:11 — forked from rndme/hashcrypt.js
Symmetric encryption using hash function and key derivation
function hashCrypt(key, plain, hasher, workFactor=1) { // hasher is any sync string-output hash function
var len=plain.length, keyLen = key.length, keyOrig = key,
// calculate derivation count based on deterministic factors from the inputs:
mx = hasher(key).split("").map((a, b)=> a.charCodeAt(0) + b).reduce((a, b)=> a + b, 0) * workFactor;
// derive firstly for some hardness using cpu and ram hungry calculations:
for(let i = 0; i < mx; i++) key = hasher(key.repeat( ((i+len) % ((workFactor || 1) * 4))+1 ));
// expand key to needed length by appending re-hashing (with counters):
@marcoonroad
marcoonroad / Hash Ladders for Shorter Lamport Signatures.md
Created October 30, 2018 14:39 — forked from karlgluck/Hash Ladders for Shorter Lamport Signatures.md
I describe a method for making Lamport signatures take up less space. I haven't seen anyone use hash chains this way before, so I think it's pretty cool.

What's this all about?

Digital cryptography! This is a subject I've been interested in since taking a class with Prof. Fred Schneider back in college. Articles pop up on Hacker News fairly often that pique my interest and this technique is the result of one of them.

Specifically, this is about Lamport signatures. There are many signature algorithms (ECDSA and RSA are the most commonly used) but Lamport signatures are unique because they are formed using a hash function. Many cryptographers believe that this makes them resistant to attacks made possible by quantum computers.

How does a Lamport Signature work?

@marcoonroad
marcoonroad / Makefile
Created October 25, 2018 03:23 — forked from jessevanherk/Makefile
A sample makefile and support files to build a love2d game for multiple platforms from linux
LOVE_BIN=/usr/bin/love
LOVE_DIR=./src/love
DIST_DIR=./src/dist
PATCH_DIR=./src/patch
BUILD_DIR=./build
BIN_DIR=./bin
LOVE_VERSION=0.9.1
GAME_NAME=MySampleGame
PRETTY_NAME=My Sample Game
@marcoonroad
marcoonroad / random.md
Created June 4, 2018 22:12 — forked from joepie91/random.md
Secure random values (in Node.js)

Not all random values are created equal - for security-related code, you need a specific kind of random value.

A summary of this article, if you don't want to read the entire thing:

  • Don't use Math.random(). There are extremely few cases where Math.random() is the right answer. Don't use it, unless you've read this entire article, and determined that it's necessary for your case.
  • Don't use crypto.getRandomBytes directly. While it's a CSPRNG, it's easy to bias the result when 'transforming' it, such that the output becomes more predictable.
  • If you want to generate random tokens or API keys: Use uuid, specifically the uuid.v4() method. Avoid node-uuid - it's not the same package, and doesn't produce reliably secure random values.
  • If you want to generate random numbers in a range: Use random-number-csprng.

You should seriously consider reading the entire article, though - it's

CvRDTs are (almost?) as general as they can be

What are you talking about, and why should I care?

Now that we live in the Big Data, Web 3.14159 era, lots of people want to build databases that are too big to fit on a single machine. But there's a problem in the form of the CAP theorem, which states that if your network ever partitions (a machine goes down, or part of the network loses its connection to the rest) then you can keep consistency (all machines return the same answer to

@marcoonroad
marcoonroad / TLDR.md
Last active November 1, 2018 18:13
TLDR

common category:

  • collection of objects
  • collection of morphisms
    • preserves identity laws
    • preserves composition laws

category of categories:

  • objects are categories
  • morphisms are functors
@marcoonroad
marcoonroad / Ownership.ml
Last active May 15, 2017 02:51
Encoding Ownership types in OCaml...
module Ownership ( ) : sig
type owner
type ('owner, 'value) owned = private 'value
val acquire : 'value -> (owner, 'value) owned
val release : (owner, 'value) owned -> 'value
end = struct
type owner = unit
type ('owner, 'value) owned = 'value
@marcoonroad
marcoonroad / Gradual.scala
Last active February 23, 2017 04:07
"Sound" minimal Gradual Typing in Scala through Implicits...
import scala.language.implicitConversions
class Unknown (value : Any) {
def coercion[ Type ] : Type =
value.asInstanceOf[ Type ]
}
implicit def promotion[ Type ] (value : Type) : Unknown =
new Unknown (value)
@marcoonroad
marcoonroad / concatenative.lua
Created October 22, 2016 16:52
Cloning optimized with clone families.
local export = { }
local weakkey = { __mode = 'k' }
local updated = setmetatable ({ }, weakkey)
local clones = setmetatable ({ }, weakkey)
local prototype = setmetatable ({ }, weakkey)
local proxy = setmetatable ({ }, weakkey)
local metatable = { }
-- we use the `prototype` relation for indexing --
-- propagation while the `clones` relation --
local prototype = require 'prototype'
local point = prototype: clone { x = 0, y = 0, }
function point: move (x, y)
self.x = self.x + x
self.y = self.y + y
end
function point: pretty ( )