Skip to content

Instantly share code, notes, and snippets.

View followben's full-sized avatar

Ben Stovold followben

View GitHub Profile
@followben
followben / gist:4272a8684458946f93dd
Last active August 29, 2015 14:15 — forked from hollance/gist:2936287
Drawing inner glow with Core Graphics
- (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 18:54
qt_dispatch_sync_to_main_queue - performSelector on main thread for GCD
void qt_dispatch_sync_to_main_queue(dispatch_block_t aBlock) {
if ([NSThread isMainThread]) {
aBlock();
} else {
dispatch_sync(dispatch_get_main_queue(), aBlock);
}
}
@followben
followben / req.sh
Last active June 4, 2018 00:01
Install requirements.txt to current conda env (or pip if the package is not available)
while read requirement; do conda install --no-update-deps --yes $requirement || pip install $requirement; done < requirements.txt
@followben
followben / prng.js
Created March 24, 2020 03:42 — forked from lpinca/prng.js
Pseudorandom number generator based on crypto.randomBytes
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);
};