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 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 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 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:43
Catch-all Redirect .htaccess
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine on
RewriteRule (.*) http://www.gamehorizonconference.com/ [R=301,L]
</IfModule>
@iandundas
iandundas / new_gist_file
Created May 20, 2013 04:42
NSJSONSerialization usage
NSDictionary *data = [NSDictionary dictionaryWithObjectsAndKeys:@"Object", @"Key" , nil];
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:data options:0 error:nil]; // can give option NSJSONWritingPrettyPrinted
NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
@iandundas
iandundas / new_gist_file
Created May 20, 2013 04:41
Format Specifiers for NSDateFormatter
NSDateFormatter specifiers:
a: AM/PM
A: 0~86399999 (Millisecond of Day)
c/cc: 1~7 (Day of Week)
ccc: Sun/Mon/Tue/Wed/Thu/Fri/Sat
cccc: Sunday/Monday/Tuesday/Wednesday/Thursday/Friday/Saturday
d: 1~31 (0 padded Day of Month)
D: 1~366 (0 padded Day of Year)
@iandundas
iandundas / new_gist_file
Created May 20, 2013 04:41
NSString format specifiers
// Format specifiers:
%@ NSString*
%d Signed Integer
%i Signed Integer
%u Unsigned Integer
%f Float / Double
%x Hexidecimal Integer
%X Hexidecimal Integer
%o Octal Integer
%zu size_t
@iandundas
iandundas / new_gist_file
Created May 20, 2013 04:40
NSDateComponents example
NSDate *today = [NSDate date];
NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
[gregorian setLocale:[NSLocale currentLocale]];
NSDateComponents *nowComponents = [gregorian components:NSYearCalendarUnit | NSWeekCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit fromDate:today];
[nowComponents setWeekday:2]; //Monday
[nowComponents setHour:0]; //1 a.m.
[nowComponents setMinute:0];
[nowComponents setSecond:0];
@iandundas
iandundas / new_gist_file
Created May 20, 2013 04:40
Node.js hot reload
/*
* This file is part of the Spludo Framework.
* Copyright (c) 2009-2010 DracoBlue, http://dracoblue.net/
*
* Licensed under the terms of MIT License. For the full copyright and license
* information, please see the LICENSE file in the root folder.
*/
var server_filename = "server.js";
@iandundas
iandundas / new_gist_file
Created May 20, 2013 04:39
Inspect Javascript Object
/* inspect a javascript object
http://codeinthehole.com/writing/inspecting-javascript-objects/
Usage: Inspect.properties(variable);
Inspect.methods(variable);
*/
var Inspect = {
TYPE_FUNCTION: 'function',
// Returns an array of (the names of) all methods
methods: function(obj) {