Skip to content

Instantly share code, notes, and snippets.

@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 / 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))))
#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>
auto socket_ = TAsyncSocket::newSocket(ev_, super::address());
std::shared_ptr<HeaderClientChannel> channel
= HeaderClientChannel::newChannel(socket_);
auto client_ = std::make_shared<ClientType>(channel);
@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 })
#!/bin/bash
concord kill --zookeeper-hosts localhost:2181 --zookeeper-path /bolt --task-id $1
#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) {}
@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);
@bigs
bigs / curry.js
Last active December 13, 2015 17:38
A cute currying function written in pure JavaScript for FUNZIES.
var curry = function (f, args, binding) {
if (typeof f !== 'function' ||
toString.call(args) !== '[object Array]') {
throw new Error('Invalid parameters');
return;
}
if (typeof binding !== 'object') {
binding = this;
}
$data['trackList'] = array(
(object) array(
'track_num' => 1,
'track_title' => 'You\'re No Good (feat. Santigold, Vybz Kartel, Danielle Haim & Yasmin)',
'track_time' => '4:32'
),
(object) array(
'track_num' => 2,
'track_title' => 'You\'re No Good (feat. Santigold, Vybz Kartel, Danielle Haim & Yasmin)',
'track_time' => '5:35'