Skip to content

Instantly share code, notes, and snippets.

@dlmanning
dlmanning / Cargo.toml
Last active April 6, 2023 10:12
Little utility to list all PR's waiting for your review in a specified repo
[package]
name = "gh-pr-cli"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
async-openai = "0.10.2"
dotenvy = "0.15.7"
@dlmanning
dlmanning / output.txt
Last active June 19, 2022 18:43
Calculate odds of recombinators
mods \ total mods in pool
desired \______________________________________________
| 1 | 2 | 3 | 4 | 5 | 6 |
-------------|-------|-------|-------|-------|-------|-------
1 | 0.667 | 0.667 | 0.633 | 0.563 | 0.500 | 0.450 |
-------------|-------|-------|-------|-------|-------|-------
2 | 0.000 | 0.333 | 0.367 | 0.267 | 0.200 | 0.160 |
-------------|-------|-------|-------|-------|-------|-------
3 | 0.000 | 0.000 | 0.200 | 0.087 | 0.050 | 0.035 |
@dlmanning
dlmanning / transducer.js
Last active April 28, 2022 21:28
tiny little transducer util made with universal-reduce
import reduce from 'universal-reduce'
const transduce = (put, initial) => (collection, ...xfs) =>
reduce(collection, (accum, value, key) =>
put(
accum,
key,
reduce(xfs, (result, xf) => xf(result), value)
),
initial
@dlmanning
dlmanning / dnd.c
Created June 15, 2021 03:45
read whether or not macOS's Do Not Disturb mode is on
#include <CoreFoundation/CoreFoundation.h>
#include <stdio.h>
int main()
{
CFStringRef DO_NOT_DISTURB = CFStringCreateWithCString(kCFAllocatorDefault, "doNotDisturb", kCFStringEncodingUTF8);
CFStringRef APP_ID = CFStringCreateWithCString(kCFAllocatorDefault, "com.apple.notificationcenterui", kCFStringEncodingUTF8);
Boolean keyExists;
@dlmanning
dlmanning / traversal.js
Created May 31, 2020 16:15
Pre and post order traversal without recursion
class Stack extends Array {
top() {
return this[this.length - 1];
}
size() {
return this.length;
}
}
@dlmanning
dlmanning / example-output-alt
Last active April 18, 2020 22:06
Runs a simulation of doing the Standford Santa Clara County serological survey 30000 times against a given population
Hypothetical distribution of study results in a population with 0% prevalence using a test with 98.5% selectivity
[0.0078, 0.0084]: |
[0.0084, 0.0090]: |
[0.0090, 0.0096]: ||
[0.0096, 0.0102]: |||||
[0.0102, 0.0108]: |||||||||
[0.0108, 0.0114]: ||||||||||||||||||
[0.0114, 0.0120]: ||||||||||||||||||||||||||||||||
[0.0120, 0.0126]: ||||||||||||||||||||||||||||||||||||||||||||||||
#include <cstddef>
#include <iomanip>
#include <iostream>
#include <sstream>
#include <string>
using namespace std;
class Foo {
public:
const fs = require('fs');
const mathWASM = fs.readFileSync('./math.wasm');
const mainWASM = fs.readFileSync('./main.wasm');
async function main() {
// Both modules will share this table
const table = new WebAssembly.Table({
element: "anyfunc",
initial: 3,
@dlmanning
dlmanning / hoverable-hoc.js
Created November 7, 2015 19:07
Simple higher-order React component to make a compoent react to hover events.
function hoverable (WrappedComponent, propName = 'hover') {
return class HoverableComponent extends Component {
constructor (props) {
super(props)
this.state = { hovered: false }
}
turnHoverOn () {
this.setState({ hovered: true })
@dlmanning
dlmanning / monty.js
Last active June 19, 2017 14:13
Simulation of the Monty Hall problem
/*
There are a certain number of doors (usually 3). Behind one is a prize. Behind the others are goats.
The contestant picks a door, and then the host removes one of the non-selected choices that did contain
the prize. The contestant is given the option to either keep their original choice, or switch to one of
the remaining doors. What should they do?
Let's simulate their potential decisions to find out!
*/
const doors = [1, 2, 3]