Skip to content

Instantly share code, notes, and snippets.

@kevincharm
kevincharm / ASN1.sol
Created November 8, 2022 13:51
ASN.1 (DER) Parser
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8;
import {BufferSlice} from "./BufferSlice.sol";
/// @title ASN1
/// @author kevincharm
/// @notice ASN.1 (DER) decoding utils
library ASN1 {
using BufferSlice for bytes;
@kevincharm
kevincharm / README.md
Created September 28, 2022 16:51
JOIN THE REDISTRIBUTION
@kevincharm
kevincharm / mergesort.circom
Last active November 5, 2022 03:35
mergesort in circom
// SPDX-License-Identifier: Apache-2.0
pragma circom 2.0.8;
// Merge sort - another variant that uses the grand product check for multiset equality,
// but requires a random seed
include "circomlib/comparators.circom";
/// @notice Merge pre-sorted left array and pre-sorted right array.
/// @param N number of elements
@kevincharm
kevincharm / Makefile.base.mk
Created April 19, 2019 13:17
Base Makefile for cross compilation with Docker
default: run
# Host rules
DOCKER_IMAGE=kevincharm/linux-x86_64-gcc-gdb:8
WORK_DIR=$$(basename `pwd`)
ROOT_DIR=`pwd`/..
DOCKER_SH=docker run -it --rm \
-v $(ROOT_DIR):/work -w /work/$(WORK_DIR) \
--security-opt seccomp=unconfined \
$(DOCKER_IMAGE) /bin/bash -c
@kevincharm
kevincharm / global.d.ts
Last active July 20, 2018 02:59
Tagged types for JSON.stringify and JSON.parse. Extended from: https://github.com/Microsoft/TypeScript/issues/19244
class Stringified<T> {
private ___stringified: T
}
interface JSON {
stringify(
value: any,
replacer?: (key: string, value: any) => any,
space?: string | number
): string
alias cb="git status | head -n 1 | cut -d' ' -f 3"
alias pull='git pull origin $(cb)'
alias push='git push origin $(cb)'
alias g='git-10x'
alias b='g branch'
function _update_ps1() {
PS1="$(~/go/bin/powerline-go -cwd-mode dironly -error $?)"
}
@kevincharm
kevincharm / day25.js
Last active December 25, 2017 13:37
👋 til next year!
// -*- node.jz -*-
let input = ''
process.stdin.on('readable', () => input += process.stdin.read() || '')
process.stdin.on('end', () => main())
function main() {
const lines = input.split('\n\n')
const [begin, perform] = lines[0].split('\n')
const initState = begin.match(/begin in state ([A-Z]+)./i)[1]
// -*- node.jz -*-
let input = ''
process.stdin.on('readable', () => input += process.stdin.read() || '')
process.stdin.on('end', () => main())
const EventEmitter = require('events')
class Program extends EventEmitter {
constructor(id) {
@kevincharm
kevincharm / day22.js
Last active December 22, 2017 16:10
nice quads
// -*- node.jz -*-
/**
* Day 22, Part 1 & 2
*
* Usage:
* input >> stdin >> node day22.js $PART $ITERATIONS
* e.g.
* `cat input.txt | node day22.js 2 10000000`
*/
// -*- node.jz -*-
const { compose, encode, decode,
rotr, rotl, flipX, flipY, print } = require('./util')
let input = ''
process.stdin.on('readable', () => input += process.stdin.read() || '')
process.stdin.on('end', () => main())
function main() {