Skip to content

Instantly share code, notes, and snippets.

Avatar

Oliver Drobnik odrobnik

View GitHub Profile
View gist:1186394
// 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 Sep 14, 2011
Dropping a shadow
View gist:1216647
- (void)animationDidStop:(CABasicAnimation *)anim finished:(BOOL)flag
{
self.layer.shadowPath = (CGPathRef)anim.toValue;
}
- (void)updateShadowWithDuration:(NSTimeInterval)duration
{
CALayer *layer = self.layer;
if (_dropShadow)
View gist:1393523
//
// NSURL+DTAppLinks.h
// DTFoundation
//
// Created by Oliver Drobnik on 11/25/11.
// Copyright (c) 2011 Cocoanetics. All rights reserved.
//
@odrobnik
odrobnik / gist:1423199
Created Dec 2, 2011
Uploading documentation to GitHub
View gist:1423199
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 Feb 10, 2012
Asynchronous Deletion
View gist:1789418
//
// 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 Feb 12, 2012
Decoding a dos date
View gist:1810427
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 Feb 16, 2012
ImageIO versus UIImageJPEGRepresentation
View gist:1845108
// 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 Apr 26, 2012
Convenience methods to add and animate a shadowPath
View gist:2499146
- (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
Control caret by dragging on Keyboard
View gist:2593533
- (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
Dropquest 2012 - Answer 1 Solution as C Program
View gist:2669542
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};