Skip to content

Instantly share code, notes, and snippets.

View oconnore's full-sized avatar

Eric O'Connor oconnore

View GitHub Profile
# ===================================================================
# Git Configuration
#
# Bundle interface:
#
# git_repo(owner, group, path, shared, remote_name, remote, force)
# git_umask(owner, group, path, shared)
# git_worktree(owner, group, path, parent, force)
# git_fetch(owner, group, path, remote)
# git_checkout(owner, group, path, remote, branch, commit)
@oconnore
oconnore / nix.cf
Created February 23, 2016 20:29
CFengine Nix promises
# ==============================================================
# Nix Configuration
# ==============================================================
bundle agent nix_setup {
files:
"/etc/nix/users"
create => "true",
perms => mog("644", "root", "root"),
copy_from => _copy_file("$(g.files)/nix_users"),
@oconnore
oconnore / Tree.h
Last active June 7, 2016 22:04
Hierarchical Tree in C++14
#pragma once
#include <algorithm>
#include <exception>
#include <map>
#include <memory>
#include <stack>
#include <stdexcept>
#include <string>
#include <utility>
@oconnore
oconnore / RawStorable.hs
Created October 7, 2015 15:37
Overlapping instances
class RawStorable a where
storeMemRaw ::
(AllocationContext b z t r, AllocationType t r) =>
a -> b -> t -> IO (Ptr a)
loadMemRaw :: Ptr a -> IO a
instance RawStorable Int where
storeMemRaw el ctx typ = storeMemRaw (WrapStorable el) ctx typ >>= return . castPtr
loadMemRaw ptr = loadMemRaw (castPtr ptr) >>= return . unwrap
@oconnore
oconnore / Build.hs
Created July 16, 2015 05:24
Haskell build
{-# LANGUAGE OverloadedStrings, ScopedTypeVariables #-}
{-# LANGUAGE DeriveDataTypeable #-}
module Main where
import Control.Exception
import Control.Failure
import Control.Applicative
import Control.Monad
import Control.Monad.Trans
@oconnore
oconnore / Threads.hs
Created March 14, 2015 00:03
Playing with Haskell Threads
import Control.Concurrent
import Control.Exception
import Control.Monad
import System.IO
import Text.Printf
import Data.Maybe
import Data.Map as Map
import Data.Set as Set
import Data.String
@oconnore
oconnore / swapsetup.sh
Created February 2, 2015 05:13
Swapsetup
#!/bin/sh
set -e
SWAPNAME="swapfile"
SWAPFILE="/var/swapfile.crypt"
MEMORY=`cat /proc/meminfo | grep MemTotal | sel -c 2`
# Next power of 2 Megabytes above reported memory
MEGABYTES=$(perl -e "use POSIX; print 2**ceil(log(ceil($MEMORY/(2**10)))/log(2))")
@oconnore
oconnore / b32rand.js
Created September 28, 2014 01:56
Random Base32 encoded strings
var b32 = require('thirty-two');
var crypto = require('crypto');
module.exports.randomStr = function(bits) {
bits = (typeof bits === 'number' && bits >= 80) ? bits : 128;
var randb32 = b32.encode(
crypto.randomBytes(Math.ceil(bits / 8))).toString('utf8');
var idx = randb32.indexOf('=');
return randb32.substr(0, idx > 0 ? idx : randb32.length);
@oconnore
oconnore / wtf-yodlee.js
Created September 9, 2014 15:15
"The password should not contain a sequence or repeated characters. For example, aaa123 is an invalid password."
// also no control characters or spaces...
var crypto = require('crypto');
var b32 = require('thirty-two');
function randomStr(n) {
var randb32 = b32.encode(crypto.randomBytes(n)).toString('utf8');
var idx = randb32.indexOf('=');
return randb32.substr(0, idx > 0 ? idx : randb32.length);
}
@oconnore
oconnore / bench.js
Last active August 29, 2015 14:04
Benchmarking fs calls
var fs = require('fs');
function chmodFile(cb) {
fs.chmod('./hello', 0644, function(err) {
cb(err);
});
}
function statFile(cb) {
fs.stat('./hello', function(err, st) {
if ((st.mode & 07777) !== 0644) {
console.log('chmodding after stat', st.mode);