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
class BaseEnum | |
include Enumerable | |
attr_reader :ctx | |
def initialize( *ctx ) | |
@ctx = ctx | |
end | |
def each( *args, &blk ) | |
return enum_for __callee__, *args unless block_given? |
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
# Author: Erik Elmore <erik@erikelmore.com> | |
# License: Public Domain | |
require 'uri' | |
require 'aws-sdk' | |
# Facilitates polling and handling queue messages. | |
class SQSMessageDispatch | |
# Configure a new SQSMessageDispatch for the given queue URL. | |
# @param queue_url [String] URL of the SQS message queue | |
# @param sqs_opts [Hash] parameters passed to Aws::SQS::Client.new (except :region) |
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
module Tracing | |
def trace_message( msg = yield ) | |
level = String(__callee__).upcase | |
puts ' ** [%s] %s: %s' % [level, self.class, msg] | |
end | |
%i[debug info warn error].each{ |m| alias_method m, :trace_message } | |
end |
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 std::io::{self, Read, BufRead}; | |
use std::cmp; | |
use std::fmt::{self, Write}; | |
const HR_BYTES_PER_LINE: usize = 16; | |
struct HexReader<T> { | |
inner: T, | |
buf: String, | |
buf_pos: usize, |
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
require 'set' | |
# Invokes the block, passing in all or some of the input. If the block throws, the block will be invoked | |
# repeatedly for a progressively smaller subset of the batch until all elements are either processed or | |
# failed. Elements contained in sub-batches which succeed are never re-tried. Returns two Arrays, the first | |
# contains all items which succeeded and the second contains all elements which failed. | |
# | |
# This can be useful when a batch API will throw when it receies one or more malformed items, but doesn't | |
# tell you which input items were at fault. | |
# |
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 error_policy = require('./error-policy'); | |
// EventEmitter example | |
const {Readable} = require('stream'); | |
class MyReadable extends Readable { | |
constructor(){ | |
super(...arguments); | |
this.policy = error_policy(e => this.emit('error', e)); | |
} |
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 {Readable, Writable} = require('stream'); | |
const PRIVATE = Symbol('private state accessor'); | |
// Writable stream that routes each chunk through one of its output streams as determined by a user-supplied fdunction. | |
// | |
// An output stream is dynamically created whenver the channel selector function returns a new channel ID. The channel | |
// IDs may be any value which can function as a Map's key. Listeners to the "channel" event will receive a new Readable | |
// channel output stream when a new channel is created. | |
// | |
// Please note that this stream respects backpressure signaled by its outputs. This means that the overall throughput |
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 strict"; | |
const {Transform} = require('readable-stream'); | |
const PRIVATE = Symbol('ConcurrentTransform private state'); | |
const NOOP_TRANSFORM = (chunk, _, done) => done(null, chunk); | |
const NOOP_FLUSH = done => done(); | |
// Transform stream which processes chunks with limited (or unlimited) concurrency | |
class ConcurrentTransform extends Transform { | |
// @param opts {Object} Stream options. Set concurrency limit with "concurrent" (default concurrency: 1) | |
constructor( opts = {} ){ |
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
# Conway's Game of Life via Python coroutines | |
# Inspired by https://effectivepython.com/2015/03/10/consider-coroutines-to-run-many-functions-concurrently/ | |
from enum import Enum | |
from collections import namedtuple | |
from itertools import islice, count, product, chain, repeat, accumulate, starmap | |
from functools import partial, lru_cache | |
from time import sleep | |
import operator as op |
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 strict"; | |
// Make predicate funtions more convenient. | |
// Works like Ruby's Symbol#to_proc, which is usually called with the unary & operator and a Symbol literal: | |
// (ruby) %w[one two three].map(&:upcase) # returns ["ONE", "TWO", "THREE"] | |
// (js) ['one', 'two', 'three'].map(toFn('toUpperCase')); // returns ["ONE", "TWO", "THREE"] | |
// (js) ['one', 'two', 'three'].map(toFn`toUpperCase`); // same as above, but called via tagged string literal | |
// @param name {String} Name of method | |
// @param ...bound_args Arguments to bind NOTE: Args cannot be bound when calling as a tagged-template | |
// @return {Function} Function to call named method with bound args on any object given at time of invocation | |
module.exports = function toFn( name, ...bound_args ){ |