This file contains hidden or 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
class AsyncTkMixin: | |
def __init__(self, *args, **kwds): | |
super().__init__(*args, **kwds) | |
self._awaiting = [] | |
self._await_loop() | |
def _await_loop(self): | |
for i in reversed(range(len(self._awaiting))): | |
coroutine, queue = self._awaiting[i] |
This file contains hidden or 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
from tkinter import ttk | |
class DebouncedEntry(ttk.Entry): | |
def __init__(self, master, delay, callback, validate=None): | |
super().__init__(master, validate="key") | |
self["validatecommand"] = self.register(self.validate), "%P" | |
self.delay = delay | |
self.callback = callback | |
self.validate = validate |
This file contains hidden or 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
struct stack { | |
struct stack* next; | |
void* data; | |
}; | |
void push(struct stack** stack, void* data) { | |
struct stack* new = malloc(sizeof *new); | |
new->next = *stack; | |
new->data = data; | |
*stack = new; |
This file contains hidden or 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
{ | |
"base": ["s", "m", "kg", "A", "K", "mol", "cd"], | |
"derived": { | |
"rad": { | |
"numerator": ["m"], | |
"denominator": ["m"] | |
}, | |
"sr": { | |
"numerator": ["m", "m"], | |
"denominator": ["m", "m"] |
This file contains hidden or 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
from heapq import heappush, heappop | |
import itertools | |
__all__ = ["PriorityQueue"] | |
class PriorityQueue: | |
sentinel = object() | |
def __init__(self): |
This file contains hidden or 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
fn main() { | |
let x = [0, 1, 2]; | |
let y: Vec<_> = x | |
.iter() | |
.scan(None, |prev, i| Some(prev.replace(i))) | |
.flatten() | |
.collect(); | |
println!("x = {:?}", x); // x = [0, 1, 2] |
This file contains hidden or 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
#!/bin/bash | |
shopt -s dotglob nullglob | |
dest="$(pwd)" | |
tempdir="$(mktemp -d)" | |
git clone --depth 1 --no-checkout --filter=blob:none "${1%%@*}" "$tempdir" | |
tag="$(tag=${1#*@}; repo="${1##*@*}"; repo="${repo:+HEAD}"; echo "${repo:-$tag}")" | |
shift | |
cd "$tempdir" | |
git checkout "$tag" -- "$@" | |
rm -rf .git |
This file contains hidden or 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 unindent = (template, ...substitutions) => { | |
const string = String.raw({ raw: template.raw || [template] }, ...substitutions).trimEnd().replace(/^\s*\n/, ''); | |
const indent = (string.match(/^[ \t]*(?=\S)/gm) || []).map(i => i.length).reduce((a, b) => Math.min(a, b)); | |
return string.replace(new RegExp(String.raw`^[ \t]{${indent}}`, 'gm'), ''); | |
}; |
This file contains hidden or 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
\[ | |
x=\sqrt[3]{-\frac{b^3}{27a^3}+\frac{bc}{6a^2}-\frac{d}{2a}+\sqrt{\left(-\frac{b^3}{27a^3}+\frac{bc}{6a^2}-\frac{d}{2a}\right)^2+\left(\frac{c}{3a}-\frac{b^2}{9a^2}\right)^3}}+\sqrt[3]{-\frac{b^3}{27a^3}+\frac{bc}{6a^2}-\frac{d}{2a}-\sqrt{\left(-\frac{b^3}{27a^3}+\frac{bc}{6a^2}-\frac{d}{2a}\right)^2+\left(\frac{c}{3a}-\frac{b^2}{9a^2}\right)^3}}-\frac{b}{3a} | |
\] |
This file contains hidden or 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
#!/usr/bin/env bash | |
exec locate -b "\\$1" "${@:2}" |