Skip to content

Instantly share code, notes, and snippets.

@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,
@Daij-Djan
Daij-Djan / CurrenySymbolForIso.mm
Created January 27, 2014 14:31
CurrenySymbolForIso function
NSString *CurrenySymbolForIso(NSString *isoCode) {
NSLocale *locale = [NSLocale currentLocale];
return [locale displayNameForKey:NSLocaleCurrencySymbol value:isoCode];
}
int main(int argc, char *argv[]) {
@autoreleasepool {
NSString *isoCode = @"GBP";
NSString *currency = CurrenySymbolForIso(isoCode);
@Daij-Djan
Daij-Djan / executeRequest.inc.php
Last active August 16, 2021 09:27
Proxy for ANY POST http request. The script can handle POST data, a custom content type, SSL, user/password credentials and 401 errors from the target.
<?php
//
// executeRequest
//
// uses cURL to run a http(s) request.
// data, contentType, user, password are all optional
//
function executeRequest($target, $data, $contentType, $user, $password, &$http_status) {
//try to send request to remote
@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 / ArrayUtils.swift
Last active February 2, 2018 20:49
Added an Array extension with contains & indexOf -- bridging to NSArray is ugly and that hides it
import Foundation
extension Array {
func contains<U: Equatable>(object:U) -> Bool {
return (self.indexOf(object) != nil);
}
func indexOf<U: Equatable>(object: U) -> Int? {
for (idx, objectToCompare) in self.enumerate() {
if let to = objectToCompare as? U {
@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 / 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
#!/bin/bash
# This has to be run from develop (NOTE: if master is your main dev branch, edit the file.)
git checkout develop
# Update our list of remotes
git fetch
git remote prune origin
# Remove local fully merged branches
//MIT
import Foundation
import Contacts
if(NSProcessInfo.processInfo().arguments.count != 2) {
print("Usage: CNPurgeGroup %GROUPNAME%")
}
else {
let groupName = NSProcessInfo.processInfo().arguments[1]
@Daij-Djan
Daij-Djan / ignoreInvalidSSL
Last active May 23, 2016 17:08
show how to properly ignore invalid ssl certificates while leaving other authentication challenges untouuched
//setup a new task
let configuration = NSURLSessionConfiguration.ephemeralSessionConfiguration()
let session = NSURLSession(configuration: configuration, delegate: self, delegateQueue: NSOperationQueue.mainQueue())
let task = session.dataTaskWithURL(url, completionHandler: handleUrlCompleted)
task.resume()
....
//url session needs to accept invalid certificates
func URLSession(session: NSURLSession, didReceiveChallenge challenge: NSURLAuthenticationChallenge, completionHandler: (NSURLSessionAuthChallengeDisposition, NSURLCredential?) -> Void) {