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
// | |
// Study on how one could use action creators instead of string literals denoting action types. | |
// | |
// Usually, in most Redux workflows, one would define string literals to distinguish action types: | |
export const USER_DID_LOG_IN = 'USER_DID_LOG_IN' | |
// It hurts performance a little, because comparing strings might be slower than comparing numbers or object identities. | |
// It also hinders maintenance, as now the maintainer has to update twice as much code should the action name change. | |
// A very simple solution to both of these issues would be using a closure instead of a string: |
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
// | |
// Logging facility | |
// | |
// Expecting to be included: | |
// <stdio.h> | |
// <inttypes.h> | |
#define _overload7(one, two, three, four, five, six, seven, x, ...) x |
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
// | |
// Convenience extensions to read images into textures. | |
// | |
import UIKit | |
import OpenGLES | |
extension DrawContext { | |
/// Make texture with an image in it. | |
public func makeTexture(id: TextureId? = nil, width: Int? = nil, height: Int? = nil, fromFileContents filename: String) -> TextureId { |
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
// | |
// Asynchronous computation control library | |
// that adds typing and chaining on top of Dispatch. | |
// | |
import class Dispatch.DispatchQueue | |
import struct Dispatch.DispatchQoS | |
/// Single unit of asynchronous computation. | |
/// | |
public class Promise<T> { |
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
""" Logging micro-facility | |
""" | |
import os | |
from time import time, strftime, gmtime | |
def log(value=None, *formatting, **named_formatting): | |
""" Record an event | |
""" | |
if value is None: |
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
// Promise to run an operation multiple times | |
// until first success or until exhaustion of attempts | |
// | |
// In case of failure, the enclosing promise | |
// is rejected using the last error. | |
// | |
// Supplied operation could be a promise. | |
// | |
// times -- how many times to try, | |
// 1 means try once and do not retry, |
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 parse_symbolic(text) | |
# Return nested list of symbols as parsed from input S-expr | |
# | |
# text -- string with an S-expr | |
# | |
lexeme = /(?<quote_run>(?<quote>['"])(?<content>.*)\k<quote>(?<!\\))|(?<whole_word>\w+)|(?<bracket>[()])/ | |
text.strip! | |
text.gsub!(lexeme) { |match| | |
first_nonempty_index = Regexp.last_match.captures.index { |x| not x.nil? } |
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
import sys | |
import functools | |
import contextlib | |
@contextlib.contextmanager | |
def indented_output(indent=4, space=chr(32)): | |
""" Precede each carriage return with some quantity of spaces. | |
While nesting `indented_output` contexts, be prepared |
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
from functools import partial, wraps | |
def curry(f): | |
""" Represent given n-ary function | |
as a sequence of unary functions. | |
Useful for function decorators with arguments. | |
Each unary function provides a closure around |