Skip to content

Instantly share code, notes, and snippets.

View dsernst's full-sized avatar
🧘‍♂️
practicing mindfulness

David Ernst dsernst

🧘‍♂️
practicing mindfulness
View GitHub Profile
@dsernst
dsernst / typecheck.js
Last active April 19, 2024 08:58
Run typescript compiler in pre-commit hook
// Run this script to check our files for type errors
// using our existing tsconfig.json settings
//
// Usage: node typecheck.js
//
const fs = require('fs')
const stripJsonComments = require('strip-json-comments')
const tsConfig = JSON.parse(stripJsonComments(fs.readFileSync('./tsconfig.json', 'utf8')))
const { exec } = require('child_process')
@dsernst
dsernst / comparing-git-add-all.md
Last active January 25, 2024 17:00
Compare `git add .` vs `git add -A`

git add . vs git add -A

Both of these will stage all files, including new files (which git commit -a misses) and deleted files.

The difference is that git add -A also stages files in higher directories that still belong to the same git repository. Here's an example:

/my-repo
  .git/
 subfolder/
@dsernst
dsernst / Secure Internet Voting.md
Last active August 2, 2022 09:40
Secure internet voting

Proof-of-Vote: A Simple Cryptosystem for Secure Internet Voting

by David Ernst, www.liquid.us

A method to democratically vote online, that provably ensures to the individual voter that their vote was cast and counted correctly, without tampering, while still protecting their vote privacy.

Note: This is designed for our issue-based liquid democracy platform, not traditional elections.

Goals:

@dsernst
dsernst / camphor.scss
Created August 17, 2020 02:51 — forked from bdno86/camphor.scss
camphor
$camphor300:'d09GMgABAAAAAQ5UABIAAAAEn0QAAQ3tAAEZmQAAAAAAAAAAAAAAAAAAAAAAAAAAG4SkahzOKgZgFotgAIosCCIJgnMRCAqLlgCKvTwBNgIkA5lwE4GnDguZdAAEIAW7bwcgDHJb0WS0WUXZkokWaBHx4wKbY7TigANIU/t980QCGzI/IkCsdbqJZwY1ZOgWDngIamw3I43435Dd+zJ1kNmKVp/DvXNAwaNm//////////////////+/NZkMZ5cAl0CpbZ3oiwloFA5GyIWNzOYVLt1bpXPX+pABI2fo5rMZpgVYIzYqgxt92ajECqUKh2G9gaOCVRC23VSRVypHfbvb7wYcwEM25WArF0esm1yKzDixrJRdcBGtcpBZTFbFbIl8LIU4gWOnEdSITqkoGrHWJ8ywn9eVFWWk3lC6m07qp1TXntHaWp6ekYHLrFoyzOXYiQnn2kWX2zqMaFBTca25vHKndPhJV66HRhQzL9lB3OT20KGTXuFHu62wm1qzoV/iTnaiLdc8o/D7B+1O94BrjSE3cia6U1A5XNp0kHmUj8IMBaeiGaiNJV7b1csb0bq8EWYo2h1TuipR+7hmYjxeZsonGLNcmgsKp5EUDCEj9SvRyxX2uMUNfINmfNqglBYNNtjtNmdwWV2ly4uQKheyDyka2RTRoQ3IEfs+0BNcGJ4Z5AnmHNpFbCKW5PsXkAzJ6VVzzVMo0fwIUpQQT67itTNRE946/NxDashl9KuAFUbZ6yW91vObh+WAMZ1mQ1J4wotF6KXHuo65X6wSz406hW/T6XZMf/6W+HGYUxCDfhyjPaoMGcWccmbYM/H35NdHTOd79Jg0ho/BDBvRy2vcg8pHsv07UYiKrDFeqzL0Qk7qCkXLuukl2EKuR3xS6VtsLEaT0BfWoDYoQ1YvEjjT729XNMYoCX3j+2ApedBG/UHLOJ7AAnfPSqdmmePsY+522MpfPaf7kf6fIJMn0/4SE6PmuI3yjyeGjWn+1qj/ukf09DE
@dsernst
dsernst / getSpreadsheetData.js
Last active February 21, 2019 04:31
getSpreadsheetData() utility function takes the name of a worksheet, then grabs all the data on the page and gives you back an array of objects, with the first row as property names.
function getSpreadsheetData(sheetName) {
// This function gives you an array of objects modeling a worksheet's tabular data, where the first items — column headers — become the property names.
var arrayOfArrays = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(sheetName || 'Sheet1').getDataRange().getValues();
var headers = arrayOfArrays.shift();
return arrayOfArrays.map(function (row) {
return row.reduce(function (memo, value, index) {
if (value) {
memo[headers[index]] = value;
}
return memo;
@dsernst
dsernst / heapsPermute.js
Last active May 15, 2018 22:53
A JavaScript implement of Heap's efficient Permutation Algorithm: https://en.wikipedia.org/wiki/Heap%27s_algorithm
var swap = function (array, pos1, pos2) {
var temp = array[pos1];
array[pos1] = array[pos2];
array[pos2] = temp;
};
var heapsPermute = function (array, output, n) {
n = n || array.length; // set n default to array.length
if (n === 1) {
output(array);
@dsernst
dsernst / visualize_complex_linked_list.md
Created September 13, 2016 09:51
How to arrange a complex linked list? For visualizing Liquid Democracy

How to arrange a complex linked list?

Given a singly linked list like this:

[
  {
    uid: 'a',
    full_name: 'Angela Augustine',
 next: 'c',

Goal: An algorithm to calculate an elected legislator's "Representation Score".

Legislative agenda

We have a set of legislative bills, uniquely identified with keys like "2016-11-01-160553" or "2017-03-07-170089", that are the agenda items of a jurisdiction's legislature.

The set grows by 40 bills per week on average. As of 2017-03-12, it has 602 elements.

Each bill has a 1-week window in which it can be voted upon by the citizens in the jurisdiction via the Liquid platform.

Voter registration

@dsernst
dsernst / get-city-by-zip.js
Created April 11, 2017 12:51
Translate zip codes into city + state
function getCityByZip(zip) {
fetch(`https://maps.googleapis.com/maps/api/geocode/json?address=${zip}`)
.then(response => response.json())
.then(response => response.results[0].formatted_address)
.then(console.log)
}

ApprovalVotingForPresident.com

What is Approval Voting?

This is how we do it now:

Plurality voting as Radio box example

This is how we could be doing it: