This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function(exports) { | |
'use strict'; | |
/* | |
activecontexts is a two level map | |
Map(object -> Map(context -> true)) | |
The second map is simply used for efficient set lookup (has) | |
*/ | |
var activecontexts = new WeakMap(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Hey Ryan, | |
I thought this would be the easiest way to answer you in 140+ characters. | |
My first point is that the entropy of a random string is not defined by the number of possible characters. If you were to randomly pick a number between 1 and 100, and I randomly picked seven 1's or 0's, my string would have more entropy | |
log(100,2) = 6.64 | |
and | |
2^7 > 2^6.64 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE OverloadedStrings, ScopedTypeVariables #-} | |
{-# LANGUAGE DeriveDataTypeable #-} | |
module Main where | |
import Control.Exception | |
import Control.Failure | |
import Control.Applicative | |
import Control.Monad | |
import Control.Monad.Trans |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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))") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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))") |