Skip to content

Instantly share code, notes, and snippets.

View william8th's full-sized avatar

William Heng william8th

  • william [at] williamheng [dot] com
  • London, United Kingdom
View GitHub Profile
@william8th
william8th / try-catch.m
Created October 13, 2015 08:38
iOS try-catch main
int main(int argc, char *argv[]) {
int retVal = -1;
@autoreleasepool {
@try {
retVal = UIApplicationMain(argc, argv, nil, nil);
}
@catch (NSException* exception) {
NSLog(@"Uncaught exception: %@", exception.description);
NSLog(@"Stack trace: %@", [exception callStackSymbols]);
@william8th
william8th / WHYPerson.h
Created November 19, 2015 14:17
Objective-C @Property
@interface WHYPerson : NSObject
@property (nonatomic) NSString *firstName;
@property (nonatomic) NSString *lastName;
@property (nonatomic) NSDate *dateOfBirth;
@property (nonatomic, readonly) NSString *fullName;
...
@end
@william8th
william8th / WHYPerson.m
Created November 19, 2015 14:22
Objective-C @Property dot syntax
#import "WHYPerson.h"
...
@implmentation WHYPerson
...
- (NSString *)doSomething {
return [NSString stringWithFormat:@"Hello, %@", [self firstName]];
// Can also be done using dot syntax as it's just a wrapper around [self firstName]
@william8th
william8th / WHYPerson.m
Last active November 19, 2015 15:25
Objective-C Instance variables
@implementation WHYPerson
...
// This is generated by the compiler (there is no need to put this line in your code)
@synthesize firstName; // Shorter version
// The above, according to Apple automatic naming convention for instance variables,
// is just doing this (add '_' prefix):
@synthesize firstName = _firstName; // Longer version
@william8th
william8th / WHYPerson.m
Created November 19, 2015 15:08
Objective-C Use ivars in init
@implementation WHYPerson
- (id)init {
self = [super init];
if (self) {
// It is recommended to use instance variables directly to initialise the object
_firstName = ...;
_lastName = ...;
_dateOfBirth = ...;
@william8th
william8th / Date deserializer crash log
Created February 4, 2016 12:11
Date deserializer crash log for Outlook-SDK-Android
02-04 06:43:30.664 9206-12182/com.bjss.williamheng.office365poc W/System.err: com.google.gson.JsonSyntaxException: 2016-04-08
02-04 06:43:30.664 9206-12182/com.bjss.williamheng.office365poc W/System.err: at com.google.gson.internal.bind.DateTypeAdapter.deserializeToDate(DateTypeAdapter.java:81)
02-04 06:43:30.674 9206-12182/com.bjss.williamheng.office365poc W/System.err: at com.google.gson.internal.bind.DateTypeAdapter.read(DateTypeAdapter.java:66)
02-04 06:43:30.674 9206-12182/com.bjss.williamheng.office365poc W/System.err: at com.google.gson.internal.bind.DateTypeAdapter.read(DateTypeAdapter.java:41)
02-04 06:43:30.674 9206-12182/com.bjss.williamheng.office365poc W/System.err: at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.read(ReflectiveTypeAdapterFactory.java:103)
02-04 06:43:30.674 9206-12182/com.bjss.williamheng.office365poc W/System.err: at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:196)
02-04 06:43:30.6
@william8th
william8th / .bash_profile
Last active September 24, 2018 10:48
My custom bash profile
export PS1="\[\033[38;5;10m\]\u\[$(tput sgr0)\]\[\033[38;5;0m\]@\h:\[$(tput sgr0)\]\[\033[38;5;15m\] \[$(tput sgr0)\]\[\033[38;5;135m\]\w\[$(tput sgr0)\]\[\033[38;5;0m\]\\$\[$(tput sgr0)\]\[\033[38;5;15m\] \[$(tput sgr0)\]"
export CLICOLOR=1
export LSCOLORS=ExFxBxDxCxegedabagacad
export GOPATH="$HOME/Code/Go"
export JAVA_HOME="/Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home"
export PATH="/usr/local/sbin:$GOPATH/bin:$JAVA_HOME/bin:$PATH"
alias ls='ls -Gfh'
alias mvnn='mvn -DskipTests=true'
@william8th
william8th / .gitconfig
Last active March 19, 2023 00:07
My custom git config
[color]
ui = auto
[color "branch"]
current = yellow reverse
local = yellow
remote = green
[color "diff"]
meta = yellow bold
frag = magenta bold
old = red bold
@william8th
william8th / ViewController.swift
Created March 23, 2016 11:31
Change cache control headers
//
// ViewController.swift
// CacheDelegate
//
// Created by Heng, William (Mobile Developer) on 23/03/2016.
// Copyright © 2016 Heng, William (Mobile Developer). All rights reserved.
//
import UIKit
@william8th
william8th / .vimrc
Last active February 6, 2018 22:43
execute pathogen#infect()
syntax on
filetype plugin indent on
set number
let g:go_highlight_functions = 1
let g:go_highlight_methods = 1
let g:go_highlight_fields = 1
let g:go_highlight_types = 1