Skip to content

Instantly share code, notes, and snippets.

View krzysztofzablocki's full-sized avatar

Krzysztof Zabłocki krzysztofzablocki

View GitHub Profile
@krzysztofzablocki
krzysztofzablocki / gist:4091783
Created November 16, 2012 23:13
Free memory on iOS
-(float) get_free_memory {
mach_port_t host_port;
mach_msg_type_number_t host_size;
vm_size_t pagesize;
host_port = mach_host_self();
host_size = sizeof(vm_statistics_data_t) / sizeof(integer_t);
host_page_size(host_port, &pagesize);
vm_statistics_data_t vm_stat;
if (host_statistics(host_port, HOST_VM_INFO, (host_info_t)&vm_stat, &host_size) != KERN_SUCCESS) {
@krzysztofzablocki
krzysztofzablocki / gist:3951446
Created October 25, 2012 08:36
Simple crossfade
[UIView transitionWithView:cell.imageView duration:0.25f options:UIViewAnimationOptionTransitionCrossDissolve animations:^{
cell.imageView.image = decompressedThumbnail;
} completion:nil];
@krzysztofzablocki
krzysztofzablocki / gist:3951442
Created October 25, 2012 08:34
Image decompression
+ (UIImage *)decompressedImageWithImage:(UIImage *)image resizeTo:(CGSize)targetSize
{
CGImageRef imageRef = image.CGImage;
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGImageAlphaInfo alphaInfo = CGImageGetAlphaInfo(imageRef);
BOOL sameSize = NO;
if (CGSizeEqualToSize(targetSize, CGSizeMake(CGImageGetWidth(imageRef), CGImageGetHeight(imageRef)))) {
targetSize = CGSizeMake(1, 1);
sameSize = YES;
}
@krzysztofzablocki
krzysztofzablocki / gist:3305468
Created August 9, 2012 16:06
UITableViewCell + representedObject
// Created by Krzysztof Zabłocki
@interface UITableViewCell (representedObject)
@property (nonatomic, strong) id representedObject;
@end
#import "UITableViewCell+representedObject.h"
#import <objc/runtime.h>
static char RepresentedObjectKey;
@krzysztofzablocki
krzysztofzablocki / gist:3240133
Created August 2, 2012 19:58
Handling dial like rotation on CCNode by using UIPanGestureRecognizer
//! for gesture recognizer support in cocos2d use https://github.com/krzysztofzablocki/CCNode-SFGestureRecognizers
- (void)handlePanGesture:(UIPanGestureRecognizer*)gestureRecognizer
{
CGPoint location = [[CCDirector sharedDirector] convertToGL:[gestureRecognizer locationInView:gestureRecognizer.view]];
static CGPoint oldLocation;
//! this will make sure that oldLocation is initialized
if (gestureRecognizer.state != UIGestureRecognizerStateBegan) {
//! we need to calculate angle difference between previous position and current one in regards to dial center
CGPoint firstDir = ccpSub(oldLocation, dial.position);
@krzysztofzablocki
krzysztofzablocki / Worst programmer ever.m
Created April 2, 2012 12:06
Who writes code like this ? Like Seriously!?
- (void)dealloc {
[percentGender release];
[percentHisto release];
[percentPS release];
[percentSmoke release];
[percentGender dealloc];
[percentHisto dealloc];
[percentPS dealloc];
[percentSmoke dealloc];
percentGender = nil;
CGContextRef bitmapContext = CGBitmapContextCreate(NULL,
rect.size.width,
rect.size.height,
CGImageGetBitsPerComponent(imageRef),
CGImageGetBytesPerRow(imageRef),
CGImageGetColorSpace(imageRef),
kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Little);