Skip to content

Instantly share code, notes, and snippets.

@echoz
echoz / gist:1426818
Created December 3, 2011 10:45
Applescript to add a prefix to all phone numbers with checking to see if they are singaporean numbers (8 digits)
tell application "Address Book"
set prefix to "+65"
repeat with p in (get people)
repeat with n in (get p's phones)
set num to ReplaceText(n's value, " ", "") of me
if (count num) is 8 then
set n's value to prefix & num
end if
@echoz
echoz / gist:1426879
Created December 3, 2011 11:08
Add groups that a contact belongs to the company field as CSVs
tell application "Address Book"
set prefix to ", "
repeat with p in (get people)
set gs to ""
repeat with g in (get p's groups)
if (gs = "") then
set gs to g's name
@echoz
echoz / gist:1482401
Created December 15, 2011 19:14
Increment current volume by 5 and plays the volume beep
-- Useful if you want to implement keyboard shortcuts with apps like Alfred App
-- Recreate this by changing the + to - for the volume down script
set curVol to (get (output volume of (get volume settings)))
set volume output volume (curVol + 5)
do shell script "afplay /System/Library/LoginPlugins/BezelServices.loginPlugin/Contents/Resources/volume.aiff"
@echoz
echoz / MNAttributedStringChange
Created May 11, 2012 13:11
MNAttributed String check of conforms to NSCoding
if (([MNAttributedString lossless]) && ([[attrs objectForKey:key] conformsToProtocol:@protocol(NSCoding)])) {
[attributes insertObject:[self _dictionaryForAttributes:[NSDictionary dictionaryWithObject:[attrs objectForKey:key] forKey:key] range:range] atIndex:([attributes count]-1)];
}
@echoz
echoz / LBCStreamWriter.h
Created May 23, 2012 18:12
Simple class that takes an input stream and writes it to a file by streaming. Duh.
//
// LBCStreamWriter.h
// LBCCore
//
// Created by Jeremy Foo on 23/5/12.
// Copyright (c) 2012 BOB FTW PTE LTD. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of
// this software and associated documentation files (the "Software"), to deal in
// the Software without restriction, including without limitation the rights to
@echoz
echoz / clang-crash.log
Created May 24, 2012 14:33
clang analyzer crash
Analyze "Classes/FacadeQueue/Network Manager/LBCNetworkManager.m"
cd /Users/jeremy/Desktop/LBCManagers
setenv LANG en_US.US-ASCII
setenv PATH "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin"
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -x objective-c -arch i386 -fmessage-length=0 -std=gnu99 -Wno-trigraphs -fpascal-strings -O0 -Wno-missing-field-initializers -Wno-missing-prototypes -Wreturn-type -Wno-implicit-atomic-properties -Wformat -Wno-missing-braces -Wparentheses -Wswitch -Wno-unused-function -Wno-unused-label -Wno-unused-parameter -Wunused-variable -Wunused-value -Wno-uninitialized -Wno-unknown-pragmas -Wno-shadow -Wno-four-char-constants -Wno-sign-compare -Wno-shorten-64-to-32 -Wpointer-sign -Wno-newline-eof -Wno-selector -Wno-strict-selector-match -Wno-undeclared-selector -Wno-deprecated-implementations -DDEBUG
@echoz
echoz / LBCHTTPPostBody.h
Created May 31, 2012 02:10
Class to generate HTTP Post Body
//
// LBCHTTPPostBody.h
// LBCCore
//
// Created by Jeremy Foo on 22/5/12.
// Copyright (c) 2012 BOB FTW PTE LTD. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of
// this software and associated documentation files (the "Software"), to deal in
// the Software without restriction, including without limitation the rights to
@echoz
echoz / gist:2842256
Created May 31, 2012 09:35
simple thread safe token generator
// _requests is a dictionary that can be mutated on any thread
// __tokenLBCURLRequestMap is just a dictionary to check if the token already is being "processed"
-(NSString *)readyToken {
if ([_requests count] == 0)
return nil;
NSMutableArray *tokens = [[[_requests allKeys] mutableCopy] autorelease];
NSString *token = nil;
@echoz
echoz / gist:2932465
Created June 14, 2012 19:42
Nothing wrong with messaging nil
// Consider an accessor setter method
-(void)setUniqueIDString:(NSString *)uid {
if (uid != _uid) {
[_uid release];
_uid = [uid copy];
}
}
// You can do [object setUniqueIDString:nil] and not crash.
@echoz
echoz / gist:3089230
Created July 11, 2012 09:18
do animation only if its supposed to be animated
-(void)doAnimated:(BOOL)animated animation:(void (^)(void))animation {
if (animated) {
[UIView animateWithDuration:0.33
delay:0.0
options:(UIViewAnimationCurveEaseInOut | UIViewAnimationOptionBeginFromCurrentState)
animations:animation
completion:nil];
} else {
animation();
}