Skip to content

Instantly share code, notes, and snippets.

@dlmanning
dlmanning / dnd.c
Created Jun 15, 2021
read whether or not macOS's Do Not Disturb mode is on
View dnd.c
#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
Pre and post order traversal without recursion
View traversal.js
class Stack extends Array {
top() {
return this[this.length - 1];
}
size() {
return this.length;
}
}
@dlmanning
dlmanning / example-output-alt
Last active Apr 18, 2020
Runs a simulation of doing the Standford Santa Clara County serological survey 30000 times against a given population
View example-output-alt
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]: ||||||||||||||||||||||||||||||||||||||||||||||||
View copy-move-semantics.cpp
#include <cstddef>
#include <iomanip>
#include <iostream>
#include <sstream>
#include <string>
using namespace std;
class Foo {
public:
View main.js
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 / monty.js
Last active Jun 19, 2017
Simulation of the Monty Hall problem
View monty.js
/*
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]
@dlmanning
dlmanning / injected.js
Created Apr 20, 2017
Script comcast injected in my http response to show me a modem ad
View injected.js
// Copyright (C) 2015 Comcast Cable Communications, LLC
// Contact Us: http://customer.xfinity.com/contact-us/
// Intended use of this message is to display critical and time sensitive notifications to customers.
/*
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
View async.js
'use strict'
const async = makeGenerator => function () {
const generator = makeGenerator.apply(this, arguments);
const handle = result =>
result.done
? Promise.resolve(result.value)
: Promise.resolve(result.value)
.then(res => handle(generator.next(res)))
@dlmanning
dlmanning / transducer.js
Last active Jan 13, 2016
tiny little transducer util made with universal-reduce
View transducer.js
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 / branchDispatch.js
Last active Dec 18, 2015
dispatch keyed values to keyed functions
View branchDispatch.js
const branchDispatch = (obj, table, defaultFn) =>
Object.entries(obj)
.map(([key, value]) =>
table[key] != null
? [key, table[key](value)]
: typeof defaultFn === 'function'
? [key, defaultFn(value)]
: [key, undefined]
)
.reduce((results, [key, value]) => {