Skip to content

Instantly share code, notes, and snippets.

View jmenter's full-sized avatar
😐

Jeff Menter jmenter

😐
View GitHub Profile
@jmenter
jmenter / gist:91e8eed4104bf58e83a1
Created December 22, 2014 20:49
Get CGContextRef from a UIView's CALayer's contents (assuming contents is a CGImageRef)
CGImageRef image = (__bridge CGImageRef)self.view.layer.contents;
CGDataProviderRef dataProviderRef = CGImageGetDataProvider(image);
CFDataRef dataRef = CGDataProviderCopyData(dataProviderRef);
void *dataBytePointer = (void *)CFDataGetBytePtr(dataRef);
CGColorSpaceRef colorSpace = CGImageGetColorSpace(image);
CGContextRef context = CGBitmapContextCreateWithData(dataBytePointer, CGImageGetWidth(image), CGImageGetHeight(image), CGImageGetBitsPerComponent(image), CGImageGetBytesPerRow(image), colorSpace, CGImageGetBitmapInfo(image), NULL, NULL);
CGContextDoWhatever(context)...
@jmenter
jmenter / NSArray+StringUtilities.m
Last active December 21, 2015 14:59
Category on NSArray for concatenating NSStrings.
@interface NSArray (StringUtilities)
- (NSString *)string;
@end
@implementation NSArray (StringUtilities)
- (NSString *)string { return [self componentsJoinedByString:@""]; }
@end
// Usage Example: NSString *test = @[ @"This", @" is", @" a", @" test." ].string;
@jmenter
jmenter / gist:9797e4dc0952219d3f875fe2d77f3b1b
Created February 20, 2017 19:42
Fake accelerometer data from iOS Simulator
- (CMAcceleration)platformSpecificAcceleration;
{
CMAcceleration acceleration = self.motionManager.accelerometerData.acceleration;
#if (TARGET_OS_SIMULATOR)
acceleration = (CMAcceleration){
UIDevice.currentDevice.orientation == UIDeviceOrientationLandscapeLeft ? -1.f :
UIDevice.currentDevice.orientation == UIDeviceOrientationLandscapeRight ? 1.f : 0.f,
UIDevice.currentDevice.orientation == UIDeviceOrientationPortrait ? -1.f :
UIDevice.currentDevice.orientation == UIDeviceOrientationPortraitUpsideDown ? 1.f : 0.f, 0.f};
#endif
@jmenter
jmenter / vImageFastBlur.c
Last active June 2, 2023 06:51
C Function to create a blurred CGimageRef (supply an image and a blur radius). Uses vImage Accelerate Framework for Mac OS X/iOS 5+ and is VERY fast.
// Assumes ARGB8888
CGImageRef CGImageCreateBlurredImage(CGImageRef inImage, NSUInteger blurRadius)
{
if (!inImage) { return NULL; }
uint32_t radius = (blurRadius % 2) ? (uint32_t)blurRadius : (uint32_t)++blurRadius;
vImage_Error error;
vImage_CGImageFormat imageFormat = {(uint32_t)CGImageGetBitsPerComponent(inImage), (uint32_t)CGImageGetBitsPerPixel(inImage), CGImageGetColorSpace(inImage), CGImageGetBitmapInfo(inImage), 0, NULL, kCGRenderingIntentDefault};
vImage_Buffer source;