Skip to content

Instantly share code, notes, and snippets.

View lionello's full-sized avatar
🇭🇰

Lio李歐 lionello

🇭🇰
View GitHub Profile
@lionello
lionello / ethereum-test-template.js
Last active July 31, 2018 08:07
Small JS template for writing Ethereum/Solidity tests
/* Use this with an overmind Procfile like this:
geth: geth --dev --rpc console
jest: pnpx jest --watchAll
*/
const ChildProcess = require('child_process')
const Web3 = require('web3')
const Assert = require('assert')
function addressOf(contract) {
return contract.options.address
@lionello
lionello / rejects.js
Created July 5, 2018 23:29
Assertion helper for async/promise methods that should fail
Assert.rejects = async function rejects (blockOrPromise, error, message) {
return new Promise((resolve,reject) => {
if (typeof blockOrPromise === 'function') {
blockOrPromise = blockOrPromise()
}
blockOrPromise.then(x => {
reject(Error('Should fail, not return ' + x))
}).catch(async err => {
if (typeof error === 'function') {
err = (await error(err)) || err
@lionello
lionello / .direnvrc
Last active August 6, 2019 08:31 — forked from sveitser/.direnvrc
#!/bin/bash
#
# Cache nix-shell environment
#
# - watches shell.nix (or default.nix), ~/.direnvrc and .envrc
# - based on https://github.com/direnv/direnv/wiki/Nix
#
use_nix() {
local shell_file=$(test -f shell.nix && echo shell.nix || echo default.nix)
if [[ ! -f "$shell_file" ]]; then return; fi
@lionello
lionello / 1password-to-pass.js
Created February 27, 2018 16:22
NodeJS script to import a 1password tab-delimited TXT file into 'pass'
#!/usr/bin/env node
const FS = require('fs')
const URL = require('url')
const Child_process = require('child_process')
const all = FS.readFileSync('pww.txt', {encoding:'utf8'})
const regex = /\n(?:"([^"]*)")?\t"([^"]*)"\t"([^"]*)"\t"([^"]*)"\t"([^"]*)"\t(?:"([^"]*)")?/mg
while (true) {
const match = regex.exec(all)
if (!match) break
@lionello
lionello / repro181.sol
Last active March 14, 2018 18:56
Repro for Geth 1.8.x `eth.call` regression
#!/usr/bin/env node
const Child_process = require('child_process')
const Web3 = require('web3')
const Assert = require('assert')
const SOL = `
contract BS {
function isValidSignature(
address signer,
bytes32 hash,
@lionello
lionello / base64url
Last active August 6, 2022 17:37
base64url: wrapper script for base64
#!/usr/bin/env bash
# Source: https://gist.github.com/lionello/6bb597fc600932c6c737aab3b402147c
ignore=0
decode=0
dashdash=0
args=()
files=()
while [ $# -gt 0 ]; do
@lionello
lionello / ModExp.sol
Last active March 17, 2022 13:07
Solidity wrapper for Ethereum Byzantium's BigInt `modexp` built-in contract 0x5
pragma solidity ^0.4.17;
contract ModExp {
// Wrapper for built-in bigint_modexp (contract 0x5) as described here https://github.com/ethereum/EIPs/pull/198
function modexp(bytes memory _base, bytes memory _exp, bytes memory _mod) public view returns(bytes memory ret) {
uint256 bl = _base.length;
uint256 el = _exp.length;
uint256 ml = _mod.length;
@lionello
lionello / androiduml.d
Last active October 20, 2017 06:27
Create PlantUML/graphviz dot activity diagram for an Android project
#!/usr/bin/env dmd -run
import std.xml;
import std.file;
import std.stdio;
Element getElementByTagName(Element parent, string name) {
foreach (child; parent.elements) {
if (child.tag.name == name) {
return child;
@lionello
lionello / optimize_eagle.d
Created September 17, 2017 01:26
Optimize paths in Eagle PCB files for faster CAM processing of GERBER files
import std.xml;
import std.file;
import std.stdio;
import std.conv;
import std.math;
real EPSILON = 1e-2;
real distance_to_line(real fx, real fy, real tx, real ty, real px, real py) {
@lionello
lionello / imageset2mipmap.js
Last active August 22, 2017 08:04
Node.JS script to losslessly convert an iOS .imageset to an Android mipmap
#!/usr/bin/env node
const FS = require('fs')
const Path = require('path')
const FolderMap = {
"1x": "mipmap-mdpi",
"2x": "mipmap-xhdpi",
"3x": "mipmap-xxhdpi",
}