Skip to content

Instantly share code, notes, and snippets.

Eric O'Connor oconnore

Block or report user

Report or block oconnore

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@oconnore
oconnore / stream-errors.js
Created May 13, 2014
Why is the last error unhandled?
View stream-errors.js
var s = require('stream');
var mys;
/* ========================================================
Error callback first, throw
======================================================== */
mys = Object.create(s.Readable.prototype);
mys._read = function(size) {
this.emit('error', new Error('test'));
@oconnore
oconnore / sel.hs
Created May 28, 2014
Line / Whitespace selection tool
View sel.hs
import System.IO
import System.Environment
import Text.Printf
import Data.Char
import Data.Set
import Data.List
import Text.Regex
import Text.Regex.Posix
printList :: [String] -> IO ()
View swapsetup.sh
#!/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 / bench.js
Last active Aug 29, 2015
Benchmarking fs calls
View bench.js
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);
@oconnore
oconnore / wtf-yodlee.js
Created Sep 9, 2014
"The password should not contain a sequence or repeated characters. For example, aaa123 is an invalid password."
View wtf-yodlee.js
// 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 / b32rand.js
Created Sep 28, 2014
Random Base32 encoded strings
View b32rand.js
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);
View swapsetup.sh
#!/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 / Threads.hs
Created Mar 14, 2015
Playing with Haskell Threads
View Threads.hs
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 / Build.hs
Created Jul 16, 2015
Haskell build
View Build.hs
{-# 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 / RawStorable.hs
Created Oct 7, 2015
Overlapping instances
View RawStorable.hs
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
You can’t perform that action at this time.