Skip to content

Instantly share code, notes, and snippets.

defmodule Foo do
use Pipe
def maybe({:ok, val}, f), do: f.(val)
def maybe({:bad, _} = lhs, f), do: lhs
def maybe(_, _), do: raise ArgumentError
def dec(num) do
if num > 0 do
{:ok, num-1}
@takscape
takscape / gist:df9925d0f18b2942feb2
Created September 13, 2014 02:52
Parsing with Sedlex and BatParserCo
#!/usr/bin/env ocamlscript
Ocaml.ocamlflags := ["-g"; "-thread"];
Ocaml.use_camlp4 := false;
Ocaml.packs := ["batteries"; "sedlex"]
--
open Batteries
(* Sedlex lexer definitions *)
type token =
| Number of int
@takscape
takscape / gist:96d154b022176455be3c
Created September 4, 2014 11:13
ocamlscript with inline unit tests
#!/usr/bin/env ocamlscript
Ocaml.ocamlflags := ["-g"; "-thread"];
Ocaml.ppopt := ["-pa-ounit-lib"; "fibo"];
Ocaml.packs := ["core"; "cfstream"; "num"; "pa_ounit.syntax"]
--
open Core.Std
open CFStream
let fibo_stream () =
@takscape
takscape / gist:3328a99227ab73c8221b
Last active August 29, 2015 14:01
Quick workaround for vim-ocp-index on Wodi environment
" ocp-index support for vim
" Maintainer: INAJIMA Daisuke <[email protected]>
" Version: 0.1
let s:ocaml_lib_dir = ""
let s:jump_history = []
let s:max_jump_history = 100
function! ocpindex#init()
@takscape
takscape / gist:7067373
Last active December 26, 2015 00:49
Stream.fromを無理やり使ったフィボナッチ数列
open Core.Std
let rec fib () =
let tmp = ref (0, 1) in
let fib_next n =
match !tmp with
| (cur, next) -> begin
tmp := (next, cur+next);
Some cur
end
@takscape
takscape / gist:5083554
Created March 4, 2013 16:36
Bro script for extracting all TCP stream contents.
@load base/utils/files
global conn_files: table[string] of file &synchronized;
redef tcp_content_deliver_all_orig = T;
redef tcp_content_deliver_all_resp = T;
event tcp_contents(c: connection, is_orig: bool, seq: count, contents: string)
{
local fname: string;
@takscape
takscape / gist:5056279
Created February 28, 2013 12:01
libnids, printall.c
static struct nids_chksum_ctl chksum_ctl;
int
main ()
{
chksum_ctl.netaddr = 0;
chksum_ctl.mask = 0;
chksum_ctl.action = NIDS_DONT_CHKSUM;
nids_register_chksum_ctl(&chksum_ctl, 1);
@takscape
takscape / gist:4736182
Created February 8, 2013 02:38
Splunk settings for LTSV
# props.conf
[ltsv]
NO_BINARY_CHECK = 1
SHOULD_LINEMERGE = false
REPORT-ltsv = ltsv-extractions
TIME_FORMAT=%d/%b/%Y:%H:%M:%S %z
TIME_PREFIX=time:
# transforms.conf
[ltsv-extractions]
@takscape
takscape / gist:4319478
Created December 17, 2012 16:10
A Python writer plugin for collectd
# -*- coding: utf-8 -*-
import collectd
import logging
import time
from logging.handlers import RotatingFileHandler
TIME_FORMAT = "%Y-%m-%d %H:%M:%S"
LOGFILE_PATH = "/var/log/collectd/values.log"
@takscape
takscape / gist:4162257
Created November 28, 2012 16:13
Testcase for reproducing issue #123
from aspen import resources, Response
from aspen.resources.negotiated_resource import NegotiatedResource
from aspen.testing import assert_raises, attach_teardown, handle, mk, StubRequest
from aspen.website import Website
from aspen.renderers.tornado import Factory as TornadoFactory
def get(**_kw):
kw = dict( website = Website([])
, fs = ''