Skip to content

Instantly share code, notes, and snippets.

@fred-o
fred-o / valuestore.ts
Created August 19, 2020 06:49
valuestore.ts
import { Semaphore } from 'await-semaphore'
import { EventEmitter } from 'events'
import Redis from 'ioredis'
import StrictEventEmitter from 'strict-event-emitter-types'
interface Events<T> {
change: (data: T) => void,
delete: void
}
#!/bin/bash
input=$1
perl -i -pe 's/^( +)(?!expect)([^ ]*q?)(\.should)/$1expect($2)$3/ ' $input
perl -i -pe 's/\.(should|to)\.(not\.)?(eql|equal)/.$2toEqual/' $input
perl -i -pe 's/\.(should|to)\.(not\.)?be.instance[oO]f/.$2toBeInstanceOf/' $input
@fred-o
fred-o / dumper.js
Last active February 7, 2020 12:52
Elasticsearch scrolling data extraction
const ElasticSearch = require('elasticsearch')
function scrollingSearch (es, index, type, size, scroll, body, stagger = 0) {
return {
[Symbol.asyncIterator]: async function* next () {
let count = 0
let r = await es.search({ index, type, size, scroll, body })
while (count < r.hits.total) {
for (let hit of r.hits.hits) {
await new Promise((resolve, reject) => setTimeout(resolve, stagger))
@fred-o
fred-o / ttninjs-dates.md
Created June 9, 2016 13:43 — forked from algesten/ttninjs-dates.md
ttninjs-dates external and internal

TTNINJS Dates

This is an attempt to document the interpretation of various date fields in the ttninjs spec. Some fields are internal to TT and not visible in metadata delivered to customers. Internal fields are prefixed _.

versioncreated

# mutators
get = ->
set = (newVal) -> (val) -> newVal
add = (inc) -> (val) -> val + inc
sub = (inc) -> (val) -> val - inc
# guards
increasing = (oldVal, newVal) -> throw Error "#{newVal} <= #{oldVal}" unless newVal > oldVal
decreasing = (oldVal, newVal) -> throw Error "#{newVal} >= #{oldVal}" unless newVal < oldVal
package app.ingester.event;
import java.util.Deque;
import java.util.Map;
import java.util.Map.Entry;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentLinkedDeque;
import java.util.concurrent.Semaphore;
import java.util.concurrent.ThreadPoolExecutor;
(ns zmq-test.core
(:import [java.io InputStream])
(:use [org.zeromq.clojure]))
(def *ctx* (make-context 0))
(defn serialize [form]
(.getBytes (with-out-str (pr form))))
(defn deserialize [bytes]
@fred-o
fred-o / gist:166391
Created August 12, 2009 08:18
clojure startup script
#!/bin/bash
# Please make sure to configure ~/.clojure.conf or /etc/clojure.conf
# sample configuration can be found at clojure.conf.sample
#
# Note, running this script will:
# - Run ~/.clojurerc on boot up (if exists)
# - Add all .jar files within clj_ext (~/.clojure on default)
# to the classpath
#