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 events = []; | |
const tasks = []; | |
function registerInterest(event, task) { | |
events.push({ event, task }); | |
} | |
function waitForEvents() { | |
if (events.length === 0) { | |
return; |
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
use miette::SourceSpan; | |
use unicode_segmentation::UnicodeSegmentation; | |
#[derive(Debug, PartialEq)] | |
pub enum TokenType { | |
// Operators: | |
Equals, // == | |
NotEquals, // != | |
Assignment, // = | |
Plus, |
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
# HT Job Vranish: https://spin.atomicobject.com/2016/08/26/makefile-c-projects/ | |
TARGET_EXEC ?= target.out | |
BUILD_DIR ?= ./build | |
SRC_DIRS ?= ./src | |
SRCS := $(shell find $(SRC_DIRS) -name *.cpp -or -name *.c -or -name *.s) | |
OBJS := $(SRCS:%=$(BUILD_DIR)/%.o) | |
DEPS := $(OBJS:.o=.d) |
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 <cassert> | |
#include <iostream> | |
#include <string> | |
#include <vector> | |
#include <stddef.h> | |
template <typename Value> | |
class Node { | |
public: | |
Node(std::string k, Value v) : m_key(k), m_value(v), m_next(nullptr) {}; |
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
""" | |
Simple dependency injection package that builds up global tree of singleton | |
objects based on __init__ params. | |
Assumes that __init__ params will be named as the snake case equivalents of | |
the required class name. So if you need an instance of UserService | |
AppContainer assumes that the param name will be `user_service`. | |
Thanks to Python's automatic super() when child does not have __init__, | |
walks the inheritance tree by default. |
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 RequireAuth = connect(mapStateToProps)( | |
({ component: Component, ...rest }) => { | |
return ( | |
<Route | |
{...rest} | |
render={props => | |
rest.isAuthenticated ? ( | |
<Component {...props} /> | |
) : ( | |
<Redirect |
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
function pretty_print(set) { | |
set.forEach(item => { | |
console.log(JSON.stringify(item)); | |
}) | |
} | |
// where set is something of the form [item, item, item] | |
function get_power_set(set) { | |
// our result will itself be a set | |
let result = []; |
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
// Callback must returns a promise. | |
// This function, unlike `Promise.all`, will resolve | |
// one promise at a time, in the original array order | |
const serial = (arr, callback) => { | |
return new Promise((resolve, reject) => { | |
arr.reduce((previous, current, index) => { | |
return previous.then(() => callback(current)).then(() => { | |
if (index === (arr.length - 1)) resolve(); | |
}).catch(e => reject(e)); | |
}, Promise.resolve()); |
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
// Simple utility function to string together parameters for a get request. | |
// For example, using this function you can do something like this: | |
// | |
// const params = stringifyParams({ | |
// param1: 'value', | |
// param2: 'otherValue', | |
// }); | |
// const url = `https://api.yourthing.com/stuff?${params}`; | |
// | |
// This url will get rendered as: |