Skip to content

Instantly share code, notes, and snippets.

@vietlq
vietlq / monad.ml
Last active June 11, 2018 15:13 — forked from eatonphil/monad.ml
Monads in OCaml
module MaybeMonad = struct
type 'a t = None | Maybe of 'a
let return (a: 'a) : 'a t = Maybe a
let (>>=) (m: 'a t) (f: 'a -> 'b t) : 'b t = match m with
| None -> None
| Maybe a -> f a
let get (m: 'a t) (a: 'a) = match m with
/**
* Base contract that all upgradeable contracts should use.
*
* Contracts implementing this interface are all called using delegatecall from
* a dispatcher. As a result, the _sizes and _dest variables are shared with the
* dispatcher contract, which allows the called contract to update these at will.
*
* _sizes is a map of function signatures to return value sizes. Due to EVM
* limitations, these need to be populated by the target contract, so the
* dispatcher knows how many bytes of data to return from called functions.
@vietlq
vietlq / ProxyFactory.sol
Created May 14, 2018 14:25 — forked from GNSPS/ProxyFactory.sol
Improved `delegatecall` proxy contract factory (Solidity) [v0.0.4]
/***
* Shoutouts:
*
* Bytecode origin https://www.reddit.com/r/ethereum/comments/6ic49q/any_assembly_programmers_willing_to_write_a/dj5ceuw/
* Modified version of Vitalik's https://www.reddit.com/r/ethereum/comments/6c1jui/delegatecall_forwarders_how_to_save_5098_on/
* Credits to Jorge Izquierdo (@izqui) for coming up with this design here: https://gist.github.com/izqui/7f904443e6d19c1ab52ec7f5ad46b3a8
* Credits to Stefan George (@Georgi87) for inspiration for many of the improvements from Gnosis Safe: https://github.com/gnosis/gnosis-safe-contracts
*
* This version has many improvements over the original @izqui's library like using REVERT instead of THROWing on failed calls.
* It also implements the awesome design pattern for initializing code as seen in Gnosis Safe Factory: https://github.com/gnosis/gnosis-safe-contracts/blob/master/contracts/ProxyFactory.sol
@vietlq
vietlq / warn_unused_result.cpp
Last active May 12, 2018 16:54
C++ (GCC / Clang): Warn on unused function result/return for safety
// https://gcc.gnu.org/onlinedocs/gcc-4.7.2/gcc/Function-Attributes.html
// https://infektor.net/posts/2017-01-19-using-cpp17-attributes-today.html
// Compiler flags: -Wall -Werror -Wextra -pedantic -Wunused-result -std=c++11
// Suggested macro names: HANDLE_OUTPUT / NODISCARD / MUST_HANDLE
#define HANDLE_OUTPUT __attribute__((warn_unused_result))
HANDLE_OUTPUT int critical_func()
{
return 1234;
@AndrewJakubowicz
AndrewJakubowicz / index.js
Created March 19, 2018 17:26
Example of using neon after `neon new ... ` step
// JS calling Rust
var addon = require('../native');
console.log(addon.hello());
// -> "hello node"
console.log(addon.adder(1,2));
// -> 3
console.log(addon.objAdder({a: 2, b: 5}));
@GNSPS
GNSPS / ProxyFactory.sol
Last active October 9, 2021 08:47
Improved `delegatecall` proxy contract factory (Solidity) [v0.0.5]
/***
* Shoutouts:
*
* Bytecode origin https://www.reddit.com/r/ethereum/comments/6ic49q/any_assembly_programmers_willing_to_write_a/dj5ceuw/
* Modified version of Vitalik's https://www.reddit.com/r/ethereum/comments/6c1jui/delegatecall_forwarders_how_to_save_5098_on/
* Credits to Jorge Izquierdo (@izqui) for coming up with this design here: https://gist.github.com/izqui/7f904443e6d19c1ab52ec7f5ad46b3a8
* Credits to Stefan George (@Georgi87) for inspiration for many of the improvements from Gnosis Safe: https://github.com/gnosis/gnosis-safe-contracts
*
* This version has many improvements over the original @izqui's library like using REVERT instead of THROWing on failed calls.
* It also implements the awesome design pattern for initializing code as seen in Gnosis Safe Factory: https://github.com/gnosis/gnosis-safe-contracts/blob/master/contracts/ProxyFactory.sol
@vietlq
vietlq / howto_nat_traversal.md
Created February 5, 2018 11:39 — forked from mildred/howto_nat_traversal.md
How To TCP NAT Traversal using Node.js and a STUN Server

How To TCP NAT Traversal using Node.js and a STUN Server

With the scarecity of IPv4 addresses, and IPv6 still not available at large, NAT traversal is becoming a necessity. Especially with the generalisation of Carrier-grade NATs that you can find on mobile connections. Even with IPv6 you may suffer NAT66. Imagine your mobile device that gets only a single Ipv6 address, and you want to share it on your computer.

The solution might be in a decentralized protocol for address attribution such

@vietlq
vietlq / pr.md
Created February 1, 2018 17:36 — forked from karlhorky/pr.md
Fetch all GitHub pull requests to local tracking branches
@vietlq
vietlq / curl.md
Created January 29, 2018 13:01 — forked from btoone/curl.md
A curl tutorial using GitHub's API

Introduction

An introduction to curl using GitHub's API.

The Basics

Makes a basic GET request to the specifed URI

curl https://api.github.com/users/caspyin
@vietlq
vietlq / docker-cleanup-resources.md
Created January 27, 2018 19:49 — forked from bastman/docker-cleanup-resources.md
docker cleanup guide: containers, images, volumes, networks

Docker - How to cleanup (unused) resources

Once in a while, you may need to cleanup resources (containers, volumes, images, networks) ...

delete volumes

// see: https://github.com/chadoe/docker-cleanup-volumes

$ docker volume rm $(docker volume ls -qf dangling=true)

$ docker volume ls -qf dangling=true | xargs -r docker volume rm