Skip to content

Instantly share code, notes, and snippets.

View iandundas's full-sized avatar

Ian Dundas iandundas

View GitHub Profile
@iandundas
iandundas / new_gist_file
Created May 20, 2013 04:44
Convert files to Unix line endings
find * -name "*.js" -print0 | xargs -0 /usr/bin/dos2unix
find * -name "*.css" -print0 | xargs -0 /usr/bin/dos2unix
find * -name "*.htm" -print0 | xargs -0 /usr/bin/dos2unix
find * -name "*.html" -print0 | xargs -0 /usr/bin/dos2unix
find * -name "*.php" -print0 | xargs -0 /usr/bin/dos2unix
#etc
#where /usr/bin/dos2unix is:
#!/bin/sh
@iandundas
iandundas / new_gist_file
Created May 20, 2013 04:44
Force HTTPS
<?php
if(empty($_SERVER['HTTPS']))
{
// If not, redirect
$newurl = 'https://'.$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];
header("location: $newurl");
exit();
}
@iandundas
iandundas / new_gist_file
Created May 20, 2013 12:55
RubyMotion: Get view controller when in terminal
# View Controller:
App.delegate.instance_variable_get("@window").rootViewController
# View Controller when using UINavigationController
App.delegate.instance_variable_get("@window").rootViewController.topViewController
@iandundas
iandundas / new_gist_file
Created May 23, 2013 14:56
Get AutoLayout Debug Trace in #RubyMotion
printf UIWindow.keyWindow._autolayoutTrace
@iandundas
iandundas / gist:c952249d343a75350972
Last active September 11, 2018 09:02
How to get response body in an AFNetworking failure block #AFNetworking
// I can never, ever remember how to do this, so here's how:
failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSData *data= error.userInfo[AFNetworkingOperationFailingURLResponseDataErrorKey];
NSString *failureResponse = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSLog(@"Failure response: %@", failureResponse);
}
@iandundas
iandundas / new_gist_file
Created May 20, 2013 04:39
PHP: Relay POST and GET requests to a new URL, and output the result
<?php
// was used when API address moved but apps were live on app store.
$ch = curl_init();
$path = $_SERVER['REQUEST_URI'];
$path = str_replace('/api/index.php','',$path);
$path = str_replace('/api/','/',$path);
@iandundas
iandundas / UIImagePickerController+cats.m
Created March 16, 2015 16:19
How to detect iOS Photo library or Camera permissions (>iOS8)
//
// Created by Ian Dundas on 16/03/15.
//
#import "UIImagePickerController+cats.h"
#import <AVFoundation/AVFoundation.h>
#import "Photos/Photos.h"
/*
example usage:
@iandundas
iandundas / theme.swift
Last active August 2, 2021 22:40
Example of creating an App Theme using structs
public protocol ThemeScheme{
var fonts: FontScheme {get}
var colours: ColourScheme {get}
}
public struct Theme: ThemeScheme{
public let fonts: FontScheme
public let colours: ColourScheme
@iandundas
iandundas / String+emoji.swift
Last active April 23, 2022 16:30
Random Emoji
// Returns a random Emoji 🌿
extension String{
func randomEmoji()->String{
let range = 0x1F601...0x1F64F
let ascii = range.startIndex + Int(arc4random_uniform(UInt32(range.count)))
let emoji = String(UnicodeScalar(ascii))
return emoji
}
}
# strip out iBooks citation
sed -E -e 's/^[ ]?[0-9]* //g' | sed -E -e 's/“[ ]?[0-9]?[ ]?//g' | sed -E -e 's/”$//g' | sed -E -e 's/^(Excerpt From).*//g'