Skip to content

Instantly share code, notes, and snippets.

@Daij-Djan
Daij-Djan / plutilIdent
Created April 8, 2014 12:40
plutilIdent: tiny quick&dirty (very) utility that checks if two given plists/strings files contain equal keys
//
// main.m
// plutilIdent
//
// Created by Dominik Pich on 08/04/14.
// Copyright (c) 2014 Dominik Pich. All rights reserved.
//
#import <Foundation/Foundation.h>
@Daij-Djan
Daij-Djan / duplicateStringsKeys.sh
Last active August 29, 2015 14:02
find duplicate strings file entries (duplicate keys! the value can differ)
#!/bin/bash
FILENAME="Localizable.strings"
DUPES=`cut -d' ' -f1 "$FILENAME" | sort | uniq -d`
while read -r line; do
echo "error: $line used multiple times -"
done <<< "$DUPES"
@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 / ReflectionHelpers.swift
Last active November 14, 2015 17:21
a helper that uses reflection to get a nsnumber object from from an (optional) Int/Bool/Double/Float property. needed in unit testing
import Foundation
@objc
class ReflectionHelpers : NSObject {
class func getNSNumberForProperty(cls: AnyObject!, name: String!) -> NSNumber! {
let m = Mirror(reflecting: cls)
let child1 = m.descendant(name)
if(child1 != nil) {
//bool
@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 / 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=""
@Daij-Djan
Daij-Djan / XMLUtils+RootNodeNameFromURL.mm
Last active December 31, 2015 11:18
gets the root node's name of a given document. Nice for quickly checking if a given XML document at least starts with the content you expect! (I use it with NSOpenPanel on OSX as well as View Controllers opening user content on IOS)
#import "XMLUtils.h"
#import <libxml/xmlreader.h>
@implementation XMLUtils
//...
+ (NSString*)rootNodeNameFromURL:(NSURL*)url {
NSString* obj = nil;
xmlTextReaderPtr reader = xmlReaderForFile( url.absoluteString.UTF8String,