Skip to content

Instantly share code, notes, and snippets.

View sander's full-sized avatar

Sander Dijkhuis sander

View GitHub Profile
@sander
sander / ChoosingBasePointsWithECDSA.java
Created April 22, 2023 14:54
Choosing base points with ECDSA
import org.bouncycastle.jce.ECNamedCurveTable;
import org.bouncycastle.jce.interfaces.ECPublicKey;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
import org.bouncycastle.jce.spec.ECParameterSpec;
import org.bouncycastle.jce.spec.ECPublicKeySpec;
import org.bouncycastle.math.ec.ECPoint;
import java.security.*;
import java.util.Base64;
@sander
sander / index.html
Created August 10, 2014 23:54
p5.js in ClojureScript
<!doctype html>
<style>body { padding: 0; }</style>
<script src='https://cdn.jsdelivr.net/p5.js/0.3.2/p5.min.js'></script>
<script src='out/goog/base.js'></script>
<script src='myproject.js'></script>
<script>goog.require('myproject.core')</script>
@sander
sander / zkp.rs
Last active November 13, 2022 20:42
Schnorr Non-interactive Zero-Knowledge Proof in Rust
//! Unevaluated prototype of IETF RFC 8235 §3.3 with §4.
// [dependencies]
// elliptic-curve = "0.12.3"
// p256 = "0.11.1"
// sha2 = "0.10.6"
use std::cmp::min;
use std::ops::{Add, Mul};
@sander
sander / ZeroKnowledgeProof.java
Last active October 26, 2022 20:13
Schnorr Non-interactive Zero-Knowledge Proof in Java
///usr/bin/env jbang "$0" "$@" ; exit $?
//DEPS org.bouncycastle:bcprov-jdk18on:1.72
import org.bouncycastle.crypto.digests.SHA256Digest;
import org.bouncycastle.jce.ECNamedCurveTable;
import org.bouncycastle.jce.spec.ECParameterSpec;
import org.bouncycastle.math.ec.ECPoint;
import java.math.BigInteger;
@sander
sander / listhash.scala
Created October 17, 2022 08:20
Cross-encoding list hashing inspired by objecthash
package listhash
enum Expr:
case Atom(value: Array[Byte] | String | Symbol) extends Expr
case Comp(value: List[Expr]) extends Expr
opaque type ListHash = Array[Byte]
/** Inspired by https://github.com/benlaurie/objecthash */
def listHash: Expr => ListHash =
import scala.util.matching.Regex
val in = """# Systems
|
|## System 1
|
|- Foo: bar
|- Baz: qux
|- Bla:
| 1. Bla
@sander
sander / figwheel.clj
Created June 27, 2015 09:41
figwheel without leiningen, requires a figwheel-sidecar dependency
(require '[figwheel-sidecar.repl-api :as repl])
(def config
{:figwheel-options {}
:build-ids ["browser"]
:all-builds [{:id "browser"
:source-paths ["src/" "env/browser/"]
:figwheel {:on-jsload "id.client/main"}
:compiler {:output-to "public/js/app.js"
:output-dir "public/js"
@sander
sander / ancs.js
Last active February 5, 2021 16:02
BLE to stdin/stdout
var bleancs = require('ble-ancs')
var t = require('transit-js')
var writer = t.writer('json')
var reader = t.reader('json')
function status(v) {
return t.map([t.keyword('type'), t.keyword('status'),
t.keyword('value'), t.keyword(v)])}
function notif(v) {
return t.map([t.keyword('type'), t.keyword('notification'),
@sander
sander / model.js
Last active October 25, 2020 14:30
Event-driven architecture prototyping in vanilla JavaScript
/**
* The following is a prototype to demonstrate how enterprise integration can be modelled using
* vanilla JavaScript. This could benefit service design: low-fidelity modelling of bounded contexts
* and messages makes ideas more tangible to explore and communicate. The model can be run inside
* an HTML page and tested using:
*
* dispatchEvent(new Event("test"));
*
* In this script I will refer to the following design domain concepts.
*/
@sander
sander / theme-switcher.php
Last active October 4, 2019 11:55
WordPress plugin to change themes based on signed in user level
<?php
// Plugin Name: Theme switcher
// Author: Sander Dijkhuis
require_once(ABSPATH . WPINC . '/pluggable.php');
function theme_switcher_callback() {
return 'alternative-theme-name';
}