Skip to content

Instantly share code, notes, and snippets.

@Daij-Djan
Daij-Djan / clean_unused_images.sh
Last active October 10, 2015 20:58
Verify and filter potentially unused files -- in our case, I used it to find missing retina images and all-together unused ones
#!/bin/sh
#vars
if [ "$#" == 0 ]; then
ROOT_FOLDER="."
else
ROOT_FOLDER=$1
fi
#we 'assume' only images here and in subfolders
IMAGES_FOLDER="./Resources/images/"
@Daij-Djan
Daij-Djan / AssociativeStorage
Created September 24, 2012 07:13
easy macros for ObjC properties in categories using AssociativeStorage!
//got from stackoverflow - quite nice :)
//http://stackoverflow.com/questions/8870197/adding-properties-to-uiviewcontroller-and-all-its-subclasses
#ifndef ASSOCIATED_STORAGE_PROPERTY_IMP
#define THREE_WAY_PASTER_INNER(a, b, c) a ## b ## c
#define THREE_WAY_PASTER(x,y,z) THREE_WAY_PASTER_INNER(x,y,z)
#define ASSOCIATED_STORAGE_PROPERTY_IMP(type, setter, getter, policy) \
static void * const THREE_WAY_PASTER(__ASSOCIATED_STORAGE_KEY_, getter, __LINE__) = (void*)&THREE_WAY_PASTER(__ASSOCIATED_STORAGE_KEY_, getter,__LINE__); \
\
- (type)getter { return objc_getAssociatedObject(self, THREE_WAY_PASTER(__ASSOCIATED_STORAGE_KEY_, getter,__LINE__) ); } \
@Daij-Djan
Daij-Djan / tunes.scpt
Created December 12, 2012 23:39
script itunes and add a track (which you specify in this script) to itunes 11's new up next list
tell application "AppleScript Utility"
set GUI Scripting enabled to true
end tell
tell application "iTunes"
--get the song
set l to playlist "Purchased"
set t to item 5 of tracks of l
--focus it in list
@Daij-Djan
Daij-Djan / NSHTTPCookieStorage+dump.h
Created January 29, 2013 09:07
dump cookies that are stored in a NSHTTPCookie storage instance. typically you use `[[NSHTTPCookieStorage sharedHTTPCookieStorage] dump];` All credits go to bladnman @ http://stackoverflow.com/questions/771498/where-are-an-uiwebviews-cookies-stored
@interface NSHTTPCookieStorage (dump)
- (void) dump;
- (void) dumpForURL:(NSURL*)url;
- (void) dumpWithMessage:(NSString *)msgOrNil forURL:(NSURL*)url;
@end
@Daij-Djan
Daij-Djan / main.mm
Last active February 2, 2018 10:29
universal main.m for iOS and OSX with or without ARC. It checks the info.plist and invokes apple's native `UIApplicationMain` or `NSApplicationMain` with the right parameters in any case. (See Comment for more info)
//
// main.m
//
// Created by Dominik Pich on 10.02.13.
// Everybody is free to use this however they want!
//
#if TARGET_OS_IPHONE
#import <UIKit/UIKit.h>
#else
#import <Cocoa/Cocoa.h>
@Daij-Djan
Daij-Djan / UIFont+Traits.h
Last active May 14, 2016 07:00 — forked from anonymous/UIFont+Traits.mm
Easy UIFont Traits Querying (isBold/ isItalic) Found this hidden gem and made it a gist: http://joshua.nozzi.name/2012/08/easy-uifont-bold-and-italic-querying-with/ - and copyng of fonts to add specific traits
#import <UIKit/UIKit.h>
#import <CoreText/CTFont.h>
@interface UIFont (Traits)
@property(nonatomic, readonly) CTFontRef CTFontRef;
@property(nonatomic, readonly) CTFontSymbolicTraits traits;
@property(nonatomic, readonly, getter=isBold) BOOL bold;
@property(nonatomic, readonly, getter=isItalic) BOOL italic;
@Daij-Djan
Daij-Djan / WebviewResponseHeaders.mm
Last active July 28, 2017 08:24
Response headers / statusCode from a UIWebView (using workaround till the webview gets extended!)
@implementation DDViewController
- (void)viewDidAppear:(BOOL)animated {
NSURL *u = [NSURL URLWithString:@"http://www.google.de"];
NSURLRequest *r = [NSURLRequest requestWithURL:u];
[self.webView loadRequest:r];
}
- (void)webViewDidFinishLoad:(UIWebView *)webView {
NSCachedURLResponse *resp = [[NSURLCache sharedURLCache] cachedResponseForRequest:webView.request];
@Daij-Djan
Daij-Djan / NSManagedObjectContext+SafeMerge.h
Created May 15, 2013 12:53
NSManagedObjectContext+SafeMerge swizzles -mergeChangesFromContextDidSaveNotification and wraps it in a @Try and catch => this isn't nice but sometimes merging fails for no good reason and this catches the exception there -- needed for GoogleMaps 1.2
#import <CoreData/CoreData.h>
@interface NSManagedObjectContext (SafeMerge)
@end
@Daij-Djan
Daij-Djan / NSAttributedString+DDTextAttachment.mm
Created October 4, 2013 02:04
This is for DTCoreText. I fiddled some time with this.. I wanted to get a custom view (not html based) into a label. I found I had forgotten setting the CTRunDelegate :/ So it wasn't resized ok. now it works ;)
@implementation NSAttributedString (DTTextAttachment)
+ (instancetype)attributedStringWithTextAttachment:(DTTextAttachment*)attachment {
NSMutableDictionary *mAttributes = [NSMutableDictionary dictionary];
[mAttributes setObject:attachment forKey:NSAttachmentAttributeName];
#if DTCORETEXT_SUPPORT_NS_ATTRIBUTES && TARGET_OS_IPHONE
// need run delegate for sizing
CTRunDelegateRef embeddedObjectRunDelegate = createEmbeddedObjectRunDelegate(attachment);
@Daij-Djan
Daij-Djan / check_if_on_github.sh
Last active December 26, 2015 15:38
Checks a folder full of subfolders if each subfolder is linked to a git repo and (in this case) if the repo is on github :)
#!/bin/bash
#config
validGitPattern1="@github.com"
echoValidRepos=0
#check git paths
for path in `ls`
do
gistfile=""