Skip to content

Instantly share code, notes, and snippets.

View Daij-Djan's full-sized avatar

Dominik Pich Daij-Djan

View GitHub Profile
@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 / 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 / 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 / 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 / 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 / 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 / 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 / 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 / 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 / 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