Skip to content

Instantly share code, notes, and snippets.

View codebje's full-sized avatar

Byron Ellacott codebje

View GitHub Profile
@codebje
codebje / index.html
Last active August 29, 2015 14:17 — forked from mbostock/.block
<!DOCTYPE html>
<meta charset="utf-8">
<body>
<script src="http://d3js.org/d3.v3.min.js"></script>
<script src="http://d3js.org/topojson.v1.min.js"></script>
<script>
var width = 960,
height = 500;
@codebje
codebje / optional.c
Last active August 29, 2015 14:22
A badly written monad in 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; };
@codebje
codebje / asn-by-iso.json
Last active August 29, 2015 14:26
Polar coordinates under tension
{"GL":[8818],"DJ":[30990,327779,327831],"JM":[3586,10292,11580,22306,30689,33576,35878,40143,63094],"PG":[17828,38009,45826,45924,55792,55829,58460,63945,132216,133137],"AT":[679,760,1109,1110,1111,1112,1113,1114,1115,1116,1117,1205,1764,1776,1853,1901,1921,2036,2049,2494,2604,2871,3190,3201,3248,3330,5385,5403,5404,5405,5423,5424,5595,6720,6798,6830,6883,8245,8333,8339,8387,8412,8437,8445,8447,8514,8540,8547,8559,8562,8596,8692,8787,8832,8971,8992,9023,12311,12382,12401,12447,12453,12547,12577,12585,12605,12614,12635,12656,12762,12766,12793,12878,12895,12930,12971,12991,13008,13022,13026,13042,13051,13064,13068,13292,13298,15498,15554,15655,15702,15733,15824,15872,15910,15927,15939,15942,16008,16049,16051,16081,16099,16105,16172,16195,16305,16314,16364,16381,20537,20684,20704,20751,20863,20935,21013,21039,21078,21079,21213,21262,21285,21303,21360,21362,21393,21406,24643,24647,24656,24708,24777,24792,24847,24864,24953,24992,25011,25012,25056,25069,25089,25126,25255,25268,25294,25445,25447,25522,25575,28701,28
@codebje
codebje / Mzero.hs
Last active October 26, 2015 03:24
Monoid with zero element
module Mzero where
import Data.Monoid
class Monoid a => MonoidZ a where
zero :: a
mconcat :: (Eq a) => [a] -> a
mconcat = go
where
@codebje
codebje / Example.java
Created November 18, 2015 04:30
How a Java 8 Stream acts as a Functor
package au.id.bje.functor;
import java.util.function.Function;
import java.util.stream.Stream;
public class Example {
static class A {}
static class B {}
static class C {}
@codebje
codebje / README.md
Created May 16, 2016 00:19
Scripts in markdown

Testing scripting in MarkDown in gists

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

Ok, that's enough of that.

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()
Set<String> results = jdbcStream.streamQuery("SELECT * FROM test_data", stream -> stream
.map(row -> row.getString("entry"))
.filter(s -> Character.isAlphabetic(s.charAt(0)))
.collect(Collectors.toSet()));
class Foo {
Foo();
Code:
0: aload_0
1: invokespecial #1 // Method java/lang/Object."<init>":()V
4: return
public boolean isEven(java.lang.Integer);
Code:
0: aload_1
#!/usr/local/bin/stack runghc
import Data.Char (toUpper)
import Data.List (uncons)
ucFirst :: String -> String
ucFirst = maybe "" (\(a,b) -> toUpper a : b) . uncons
process :: String -> [String]
process s =
let slug = mconcat $ map ucFirst $ words s