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
trait Truthy: Sized { | |
fn is_truthy(&self) -> bool; | |
fn as_option(self) -> Option<Self> { | |
if self.is_truthy() { | |
Some(self) | |
} else { | |
None | |
} | |
} | |
fn or(self, default: Self) -> 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
trait Truthy: Sized { | |
fn is_truthy(&self) -> bool; | |
fn as_option(self) -> Option<Self> { | |
if self.is_truthy() { | |
Some(self) | |
} else { | |
None | |
} | |
} | |
} |
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
import {memoize} from "lodash" | |
/** | |
* Helper for passing a callback to each component in a loop. Given a callback | |
* with the signature (key, ..args), returns a new factory with the signature | |
* (key) => (...args). When called with a key, returns a wrapper function taking | |
* (...args) wich calls the original callback. This wrapper function is guaranteed | |
* to be the same for any given key. | |
* | |
* The callback must have NO dependencies that might change between renders. It |
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 | |
# This function adds an additional command to the trap stack. Each command | |
# added in this way will be called in reverse order when the signal is received. | |
# | |
# This function works with a simple concatenation with the currently existing | |
# trap function. Popping something from the trap stack without running it is | |
# left as an exercise to the reader; it requires at least a parser capable of | |
# matching { } correctly. | |
# |
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
#include <stdio.h> | |
#include <stdlib.h> | |
#include <stdarg.h> | |
/** | |
* Write a message to stderr, followed by a newline, then exit the program. | |
* This helper function is provided because C doesn't have throwable exceptions | |
* or any similarly ergonomic error handling. | |
* | |
* Arguments to this function are similar to `fprintf`; see online documentation |
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
import itertools | |
import functools | |
def keyed_product(**iterables): | |
''' | |
Same as itertools.product, but returns key-value dicts. Basically, given | |
a dict of key => list, return every possible combination of all the | |
values in the lists, and their associated keys. |
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
import itertools | |
import functools | |
def keyed_product(**iterables): | |
''' | |
Same as itertools.product, but returns key-value dicts. Basically, given | |
a dict of key => list, return every possible combination of all the | |
values in the lists, and their associated keys. |
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
import itertools | |
import functools | |
def keyed_product(**iterables): | |
''' | |
Same as itertools.product, but returns key-value dicts. Basically, given | |
a dict of key => list, return every possible combination of all the | |
values in the lists, and their associated keys. |
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
def get_rows(selected_table): | |
for row in selected_table.css('tr'): | |
cells = row.css('td').extract() | |
yield tuple(cells) | |
def find_bge_table(response): | |
for table_element in response.css('table'): | |
table = list(get_rows(table_element)) | |
if any(row[0] == "BGE" for row in table): |
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
// Create a promise that is resolved after `timeout` ms | |
const promiseTimer = timeout => new Promise(resolve => setTimeout(() => resolve(null), timeout)) | |
async function counter(max) { | |
for(let i = 0; i < max; i++) { | |
console.log("Counting:", i) | |
// This is the important part. "await" allows the function to appear to block; | |
// other asynchronous work can be done here. This is basically the equivelent | |
// of a .then on promiseTimer |