Skip to content

Instantly share code, notes, and snippets.

View willmtemple's full-sized avatar

Will Temple willmtemple

View GitHub Profile
import dbus
import os
if __name__ == '__main__':
bus = dbus.SystemBus()
mgr = bus.get_object('org.freedesktop.login1',
'/org/freedesktop/login1')
mgr_iface = dbus.Interface(
mgr, dbus_interface='org.freedesktop.login1.Manager')

Keybase proof

I hereby claim:

  • I am willmtemple on github.
  • I am wtemple (https://keybase.io/wtemple) on keybase.
  • I have a public key whose fingerprint is 8716 1D51 FFE7 FACF F586 F0A5 FB80 B041 FBEC BF47

To claim this, I am signing this object:

// Notes on how to deal with callbacks in pxexec-runtime
/**
* In pxexec-runtime, program threads run in actual separate threads called
* Fibers. Fibers are concurrent in the same way that Operating System threads
* are concurrent: each has its own stack, and they are intermittently switched
* to give the appearance of multitasking. In some cases, they may run
* simultaneously on different processors.
*
* At the same time, Node events are processed on the global event-loop. All
// Read: a DemoEnum is either a Foo(i32) or a Bar(String)
enum DemoEnum {
Foo(i32),
Bar(String),
}
fn main() {
let elts: Vec<DemoEnum> = vec![
DemoEnum::Foo(10001),
DemoEnum::Bar(String::from("Hello world!")),
const values = [
{ kind: "Foo", n: 10001 },
{ kind: "Bar", s: "Hello world!" }
];
function match(value, pattern, discriminant = "kind") {
return pattern[value[discriminant]]?.(value);
}
for (const value of values) {
type DemoEnum = Foo | Bar;
interface Foo {
kind: "Foo",
n: number
}
interface Bar {
kind: "Bar",
s: string
interface DemoEnumPatternMap<T> {
Foo: (foo: Foo) => T,
Bar: (bar: Bar) => T
}
function matchDemoEnum<T>(value: DemoEnum, pattern: DemoEnumPatternMap<T>) : T {
switch (value.kind) {
case "Foo":
return pattern.Foo(value);
case "Bar":
@willmtemple
willmtemple / ultimateMatcher.ts
Last active February 25, 2020 03:31
ultimateMatcher.ts
declare export function match<
DiscriminatedUnion extends { [K in Discriminator]: string | number },
Pattern extends Partial<
{
[K in DiscriminatedUnion[Discriminator]]: (
v: Extract<DiscriminatedUnion, { kind: K }>
) => any;
}
>,
Discriminator extends string | number = "kind"
@willmtemple
willmtemple / index.ts
Last active June 29, 2020 18:16
magic typescript function that returns its arguments' AST
// This uses my modified version of typescript from my branch github.com/willmtemple/typescript#alchemy
import * as ts from "typescript/built/local/typescript";
import * as fs from "fs";
import * as os from "os";
import { promisify } from "util";
const readFile = promisify(fs.readFile);
@willmtemple
willmtemple / lib.rs
Last active July 22, 2020 18:57
RSX - HTML in Rust
mod utils;
use wasm_bindgen::prelude::*;
mod vdom;
use vdom::*;
mod dom;
use dom::mount;