Skip to content

Instantly share code, notes, and snippets.

Avatar

Byron Ellacott codebje

View GitHub Profile
@codebje
codebje / cabal.nix
Last active Aug 7, 2018
Version of cabal.nix that can be retrieved directly from the gist
View cabal.nix
{ basePath ? ./.}:
with builtins; rec {
cabalProjects = listToAttrs (if pathExists (basePath + "/cabal.project")
then projectParse
else [ { name = baseNameOf basePath; value = basePath; } ] );
projectParse = let
contents = readFile (basePath + "/cabal.project");
trimmed = replaceStrings ["packages:" " "] ["" ""] contents;
packages = filter (x: isString x && x != "") (split "\n" trimmed);
package = p: substring 0 (stringLength p - 1) p;
@codebje
codebje / cabal.nix
Created Aug 7, 2018
Build a multi-project Cabal application with Nix
View cabal.nix
with builtins; rec {
cabalProjects = listToAttrs (if pathExists ./cabal.project
then projectParse
else [ { name = baseNameOf ./.; value = ./.; } ] );
projectParse = let
contents = readFile ./cabal.project;
trimmed = replaceStrings ["packages:" " "] ["" ""] contents;
packages = filter (x: isString x && x != "") (split "\n" trimmed);
package = p: substring 0 (stringLength p - 1) p;
paths = map (p: let p' = package p; in { name = p'; value = toPath (./. + "/${p'}"); } ) packages;
@codebje
codebje / gist:8c86ccbf1f819f119d88648833613be4
Last active Feb 22, 2017
Sequential writing of volatile (C) and atomic (C++) and dead-store elimination
View gist:8c86ccbf1f819f119d88648833613be4
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
volatile char toggle = 1;
void *writer(void *unused) {
for (;;) {
toggle = 1;
toggle = 2;
View search_deep.hs
module Search_Deep where
import Data.Bits
data Fun = And | Add | Xor | Or | Sub | Bus
data Shape = F Shape Shape | Var | Tok
data Expr a = C Fun (Expr a) (Expr a) | V a | T
data U = U
instance Show U where
showsPrec _ U = ("?" ++)
View Dockerfile
FROM ubuntu:xenial
ENV DEBIAN_FRONTEND noninteractive
RUN rm -rf /var/lib/apt/lists/* && \
apt-get update -q -q && \
echo 'UTC' > /etc/timezone && \
dpkg-reconfigure tzdata
COPY postfix_3.0.4-5ubuntu1_amd64.deb /root/
View proc.hs
#!/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
View Foo.bytecode
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
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()
@codebje
codebje / README.md
Created May 16, 2016
Scripts in markdown
View README.md

Testing scripting in MarkDown in gists

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

Ok, that's enough of that.

@codebje
codebje / Example.java
Created Nov 18, 2015
How a Java 8 Stream acts as a Functor
View Example.java
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 {}