Skip to content

Instantly share code, notes, and snippets.

Avatar
😐

Jeff Menter jmenter

😐
View GitHub Profile
@jmenter
jmenter / gist:9797e4dc0952219d3f875fe2d77f3b1b
Created Feb 20, 2017
Fake accelerometer data from iOS Simulator
View gist:9797e4dc0952219d3f875fe2d77f3b1b
- (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 / gist:91e8eed4104bf58e83a1
Created Dec 22, 2014
Get CGContextRef from a UIView's CALayer's contents (assuming contents is a CGImageRef)
View gist:91e8eed4104bf58e83a1
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 / vImageFastBlur.c
Last active Jul 29, 2019
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.
View vImageFastBlur.c
// 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;
@jmenter
jmenter / NSArray+StringUtilities.m
Last active Dec 21, 2015
Category on NSArray for concatenating NSStrings.
View NSArray+StringUtilities.m
@interface NSArray (StringUtilities)
- (NSString *)string;
@end
@implementation NSArray (StringUtilities)
- (NSString *)string { return [self componentsJoinedByString:@""]; }
@end
// Usage Example: NSString *test = @[ @"This", @" is", @" a", @" test." ].string;
You can’t perform that action at this time.