This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#![feature(box_patterns)] | |
#[derive(Debug)] | |
#[derive(Clone)] | |
pub enum Syntax { | |
Param(usize), | |
Constant(i32), | |
SymbolicValue, | |
Add(Box<Syntax>, Box<Syntax>), | |
Mul(Box<Syntax>, Box<Syntax>), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def refineddir(obj): | |
return tuple(prop for prop in dir(obj) if not prop.startswith("_") and not hasattr(getattr(obj, prop), "__call__")) | |
class DeepComparator: | |
def __init__(self, wrap): | |
self.wrap = wrap | |
def __eq__(self, other): | |
if isinstance(self, DeepComparator): | |
self = self.wrap | |
if isinstance(other, DeepComparator): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
enum discriminateFunc { | |
NO_RETURN, | |
INT_RETURN, | |
INT_RETURN_TAKE_INT, | |
}; | |
union funcUnion { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// i++ | |
interface Inc<T> { | |
1: Inc<this> | |
t: T | |
} | |
// i-- | |
interface Dec<T> { | |
0: T extends Inc<infer T> ? T : never | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Manage a table of IP addresses | |
* Supports the following operations: | |
* adding an IP | |
* removing an IP | |
* checking if an IP is in the table | |
* iterating all IP addresses inside the table | |
*/ | |
/** |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let rejectA; | |
const promA = new Promise((_, _reject) => rejectA = _reject); | |
let rejectB; | |
const promB = new Promise((_, _reject) => rejectB = _reject); | |
async function* foo() { | |
try { | |
await promA.finally(() => console.log("Promise A no longer pending")); | |
await promB.finally(() => console.log("Promise B no longer pending")); | |
} catch (e) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const pure = Symbol("pure function"); | |
const scanDone = Symbol(); | |
function scanParam(func) { | |
if (func.length !== 1) { | |
throw "Only works with unary functions"; | |
} | |
const shape = {}; | |
try { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Bindable method for flattening iterables | |
* @this {Iterable<T>} | |
* @param {(item: T) => J | void} mapper | |
* @returns flattened version of iterable with elements mapped | |
* if a mapper function was given | |
*/ | |
export function *flattenAll(mapper = v => v) { | |
for (const item of this) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Spencer Killen | |
* CMPT 360 | |
* Assignment 3 | |
* Dec 5th 2016 | |
* Library used for applying a file lock after a condition is met | |
*/ | |
#include <sys/inotify.h> | |
#include <aio.h> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface EventRegister<T> { | |
event: keyof T, | |
// any used here because ts is picky, doesn't make a difference | |
// may be able to replace with T[keyof T] in future versions | |
callback: {(data: any): void}, | |
once: boolean | |
} | |
/** | |
* Basic callback based publish / subscribe baseclass |