Skip to content

Instantly share code, notes, and snippets.

@bigs
bigs / pubsub.thrift
Last active November 17, 2015 20:11
// feel free to add a `namespace` annotation here for your chosen language
namespace py concord.pubsub
namespace rb Concord.PubSub
namespace cpp concord.pubsub
namespace java concord.pubsub
service PubSubBroker {
// subscribe / unsubscribe a new consumer to a topic
void subscribe(1:string topic, 2:string host, 3:i32 port);
void unsubscribe(1:string topic, 2:string host, 3:i32 port);
#pragma once
#include <chrono>
#include <concord/time_utils.hpp>
namespace bolt {
class SnowflakeWorker {
public:
SnowflakeWorker(const uint8_t datacenterId, const uint8_t workerId)
: datacenterId_(datacenterId), workerId_(workerId) {}
#!/bin/bash
concord kill --zookeeper-hosts localhost:2181 --zookeeper-path /bolt --task-id $1
@bigs
bigs / state.scala
Created June 22, 2015 18:07
state monad in scala?????
case class State[S, A](runState: S => (A, S)) {
def flatMap[B](f: A => State[S, B]): State[S, B] = State({
s: S =>
val (res, s1) = runState(s)
f(res).runState(s1)
})
def >>=[B](f: A => State[S, B]): State[S, B] = flatMap(f)
def >>[B](f: State[S, B]): State[S, B] = flatMap({ _ => f })
auto socket_ = TAsyncSocket::newSocket(ev_, super::address());
std::shared_ptr<HeaderClientChannel> channel
= HeaderClientChannel::newChannel(socket_);
auto client_ = std::make_shared<ClientType>(channel);
#ifndef BOLT_SUBPROCESS_HARNESS_HPP
#define BOLT_SUBPROCESS_HARNESS_HPP
#include <gtest/gtest.h>
#include <glog/logging.h>
#include <folly/Subprocess.h>
#include <folly/String.h>
#include <fstream>
#include <vector>
#include <string>
#include <algorithm>
@bigs
bigs / replace_sel_in_file.el
Last active August 29, 2015 14:05
replace instances of the word at the cursor (or current selection) with a new word
(defun cole-foo-balls (beg end r)
(interactive "r\nsReplace sel. with: ")
(let ((s (if (use-region-p)
(buffer-substring-no-properties beg end)
(word-at-point))))
(progn
(goto-char 0)
(replace-regexp s r))))
@bigs
bigs / lambda.js
Last active August 29, 2015 13:56
lambda functions in javascript
var lambda = function (str) {
var res = str.match(/^\s*([a-z]+(?:\s+[a-z]+)*)\s*\->\s*(.+?)\s*$/);
if (!res) {
throw new Error('Invalid lambda expression');
}
var args = res[1].replace(/\s{2,}/g, ' ').split(' ')
, body = 'return ' + res[2] + ';';
@bigs
bigs / lenses.md
Last active November 24, 2019 00:55
Musings on Lenses

Cole Brown

SPJ recently gave a fantastic talk on Edward Kmett's wildly useful lens library. Simon,a brilliant programmer and one of Haskell's designers, had little to no experience with lens prior to this talk and, resultingly, is able to offer a shockingly fresh perspective.

In his talk, he walks the audience through his deconstruction of the library — an illuminating journey. There is a lot of insight exposed, but there was one (perhaps unspoken) sentiment that struck me:

Functional programmers tend to prefer simple, versatile data structures like lists and trees. The reasoning is often times simple: simple data types yield powerful abstractions. One can implement a mind-boggling number of algorithms using maps and folds over lists (and associative lists).

While Haskell caters to this simplified model of programming, Haskell's type system and record syntax also encourage the use of abstract data ty

@bigs
bigs / angular-debounce.js
Last active December 24, 2015 22:59
a debounce directive for angular.js
/*
Usage
----------------
HTML
<input type="text"
ng-model="fooVal"
ng-debounce="foo()"
ng-debounce-millis="500">