Skip to content

Instantly share code, notes, and snippets.

View odrobnik's full-sized avatar

Oliver Drobnik odrobnik

View GitHub Profile
@odrobnik
odrobnik / gist:1186394
Created September 1, 2011 15:17
NSString md5
// method to calculate a standard md5 checksum of this string, check against: http://www.adamek.biz/md5-generator.php
- (NSString * )md5
{
const char *cStr = [self UTF8String];
unsigned char result [CC_MD5_DIGEST_LENGTH];
CC_MD5( cStr, strlen(cStr), result );
return [NSString
stringWithFormat: @"%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X",
result[0], result[1],
@odrobnik
odrobnik / gist:1216647
Created September 14, 2011 14:05
Dropping a shadow
- (void)animationDidStop:(CABasicAnimation *)anim finished:(BOOL)flag
{
self.layer.shadowPath = (CGPathRef)anim.toValue;
}
- (void)updateShadowWithDuration:(NSTimeInterval)duration
{
CALayer *layer = self.layer;
if (_dropShadow)
//
// NSURL+DTAppLinks.h
// DTFoundation
//
// Created by Oliver Drobnik on 11/25/11.
// Copyright (c) 2011 Cocoanetics. All rights reserved.
//
@odrobnik
odrobnik / gist:1423199
Created December 2, 2011 13:12
Uploading documentation to GitHub
mkdir gh-pages
cd gh-pages
git init
git remote add origin git@github.com:Cocoanetics/DTWebArchive.git
git symbolic-ref HEAD refs/heads/gh-pages
# add and commit files
git push origin gh-pages
@odrobnik
odrobnik / gist:1789418
Created February 10, 2012 12:42
Asynchronous Deletion
//
// DTAsyncFileDeleter.m
// DTFoundation
//
// Created by Oliver Drobnik on 2/10/12.
// Copyright (c) 2012 Cocoanetics. All rights reserved.
//
#import "DTAsyncFileDeleter.h"
@odrobnik
odrobnik / gist:1810427
Created February 12, 2012 19:40
Decoding a dos date
long l = 1078768689;
// dosdate spec: http://msdn.microsoft.com/en-us/library/windows/desktop/ms724247(v=vs.85).aspx
int year = ((l>>25)&127) + 1980; // 7 bits
int month = (l>>21)&15; // 4 bits
int day = (l>>16)&31; // 5 bits
int hour = (l>>11)&31; // 5 bits
int minute = (l>>5)&63; // 6 bits
int second = (l&31) * 2; // 5 bits
@odrobnik
odrobnik / gist:1845108
Created February 16, 2012 14:10
ImageIO versus UIImageJPEGRepresentation
// UIImageJPEGRepresentation
NSData *data = UIImageJPEGRepresentation(tileImage, 0.71);
[data writeToURL:cacheURL atomically:YES];
// ImageIO
#import <ImageIO/ImageIO.h>
#import <MobileCoreServices/UTCoreTypes.h>
@odrobnik
odrobnik / gist:2499146
Created April 26, 2012 12:03
Convenience methods to add and animate a shadowPath
- (void)addShadowWithColor:(UIColor *)color alpha:(CGFloat)alpha radius:(CGFloat)radius offset:(CGSize)offset
{
self.layer.shadowOpacity = alpha;
self.layer.shadowRadius = radius;
self.layer.shadowOffset = offset;
if (color)
{
self.layer.shadowColor = [color CGColor];
}
@odrobnik
odrobnik / gist:2593533
Created May 4, 2012 09:18
Control caret by dragging on Keyboard
- (void)keyboardWillShow:(NSNotification *)notification
{
NSArray *appWindows = [[UIApplication sharedApplication] windows];
UIWindow *keyboardWindow = [appWindows lastObject];
UIView *keyboardView = [keyboardWindow.subviews objectAtIndex:0];
keyboardView = [keyboardView.subviews objectAtIndex:0];
keyboardView = [keyboardView.subviews objectAtIndex:0];
keyboardView = [keyboardView.subviews objectAtIndex:0];
@odrobnik
odrobnik / gist:2669542
Created May 12, 2012 22:43
Dropquest 2012 - Answer 1 Solution as C Program
int test(int a, int b, int c, int d, int e)
{
if ((a*b) != 24) return 0;
if (d != (b/2)) return 0;
if ((a+c)!=(d+e)) return 0;
if ((a+b+c+d+e) != 26) return 0;
// count occurences of digits
int counts[10] = {0,0,0,0,0,0,0,0,0,0};