Skip to content

Instantly share code, notes, and snippets.

Avatar

Ben Stovold followben

View GitHub Profile
@followben
followben / prng.js
Created Mar 24, 2020 — forked from lpinca/prng.js
Pseudorandom number generator based on crypto.randomBytes
View prng.js
var crypto = require('crypto')
, rrange = 4294967296;
/**
* Return an integer, pseudo-random number in the range [0, 2^32).
*/
var nextInt = function() {
return crypto.randomBytes(4).readUInt32BE(0);
};
@followben
followben / req.sh
Last active Jun 4, 2018
Install requirements.txt to current conda env (or pip if the package is not available)
View req.sh
while read requirement; do conda install --no-update-deps --yes $requirement || pip install $requirement; done < requirements.txt
@followben
followben / gist:4272a8684458946f93dd
Last active Aug 29, 2015 — forked from hollance/gist:2936287
Drawing inner glow with Core Graphics
View gist:4272a8684458946f93dd
- (CGImageRef)createMaskFromAlphaChannel:(UIImage *)image
{
size_t width = image.size.width;
size_t height = image.size.height;
NSMutableData *data = [NSMutableData dataWithLength:width*height];
CGContextRef context = CGBitmapContextCreate(
[data mutableBytes], width, height, 8, width, NULL, kCGImageAlphaOnly);
@followben
followben / qt_dispatch_sync_to_main_queue.m
Created May 30, 2012
qt_dispatch_sync_to_main_queue - performSelector on main thread for GCD
View qt_dispatch_sync_to_main_queue.m
void qt_dispatch_sync_to_main_queue(dispatch_block_t aBlock) {
if ([NSThread isMainThread]) {
aBlock();
} else {
dispatch_sync(dispatch_get_main_queue(), aBlock);
}
}