Skip to content

Instantly share code, notes, and snippets.


Byron Ellacott codebje

View GitHub Profile
View index.html
<!DOCTYPE html>
<meta charset="utf-8">
<script src=""></script>
<script src=""></script>
var width = 960,
height = 500;
codebje / optional.c
Last active Aug 29, 2015
A badly written monad in C
View optional.c
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define OPTIONAL_INIT(t) typedef struct optional_ ## t { short isPresent; t value; } optional_ ## t
#define OPTIONAL(t) optional_ ## t
static short _optional_empty = 0;
struct optional_any { short isPresent; int value; };
public <T> T streamQuery(String sql, Function<Stream<SqlRowSet>, ? extends T> streamer, Object... args) {
return jdbcTemplate.query(sql, resultSet -> {
final SqlRowSet rowSet = new ResultSetWrappingSqlRowSet(resultSet);
final boolean parallel = false;
// The ResultSet API has a slight impedance mismatch with Iterators, so this conditional
// simply returns an empty iterator if there are no results
if (! {
return streamer.apply(, parallel));
Set<String> results = jdbcStream.streamQuery("SELECT * FROM test_data", stream -> stream
.map(row -> row.getString("entry"))
.filter(s -> Character.isAlphabetic(s.charAt(0)))
codebje / asn-by-iso.json
Last active Aug 29, 2015
Polar coordinates under tension
View asn-by-iso.json
codebje / Mzero.hs
Last active Oct 26, 2015
Monoid with zero element
View Mzero.hs
module Mzero where
import Data.Monoid
class Monoid a => MonoidZ a where
zero :: a
mconcat :: (Eq a) => [a] -> a
mconcat = go
codebje /
Created Nov 18, 2015
How a Java 8 Stream acts as a Functor
import java.util.function.Function;
public class Example {
static class A {}
static class B {}
static class C {}
codebje /
Created May 16, 2016
Scripts in markdown

Testing scripting in MarkDown in gists

<script type="text/javascript"> document.write('hello, world!'); </script>

Ok, that's enough of that.

View ghcimport.vim
command! -buffer -nargs=0 -bang GhcModImport call Autoimport(<bang>0)
function! Autoimport(force) "{{{
let l:identifier = ghcmod#getHaskellIdentifier()
let l:parts = split(l:identifier, '\.')
" `ghc-mod sig` is available since v5.0.0.
let l:cmd = ghcmod#build_command(['find', l:parts[-1]])
let l:lines = split(ghcmod#system(l:cmd), '\n')
if len(l:lines) >= 1
let l:module = l:lines[0]
let l:view = winsaveview()
View Foo.bytecode
class Foo {
0: aload_0
1: invokespecial #1 // Method java/lang/Object."<init>":()V
4: return
public boolean isEven(java.lang.Integer);
0: aload_1