Skip to content

Instantly share code, notes, and snippets.

View hlxwell's full-sized avatar
⛷️
Focusing

Michael He hlxwell

⛷️
Focusing
View GitHub Profile
@hlxwell
hlxwell / new_gist_file
Created May 2, 2013 03:06
Archive/Unarchive object to/from file
[NSKeyedArchiver archiveRootObject:Object toFile:filePath]
[NSKeyedUnarchiver unarchiveObjectWithFile:filePath]
@hlxwell
hlxwell / new_gist_file
Created May 2, 2013 03:16
Define a static method, for escape string
static NSString* GAEscapeNSString(NSString* value) {
if (!value) return nil;
const char *chars = [value UTF8String];
NSMutableString *escapedString = [NSMutableString string];
while (*chars) {
if (*chars == '\\') {
[escapedString appendString:@"\\\\"];
} else if (*chars == '\'') {
[escapedString appendString:@"\\'"];
} else {
@hlxwell
hlxwell / new_gist_file
Created May 2, 2013 03:22
Throw exception
@throw [NSException exceptionWithName:@"GAJSException"
reason:@"Failed to load JavaScriptEngine"
userInfo:nil];
@hlxwell
hlxwell / new_gist_file
Created May 2, 2013 03:54
Simple popup in Mac
NSRunAlertPanel(@"Tracker already running", @"The Tracker is already running.", @"OK", nil, nil);
@hlxwell
hlxwell / new_gist_file
Created May 5, 2013 05:32
Replace placeholder in string
"%s %s" % ["a", "b"] => "a b"
@hlxwell
hlxwell / new_gist_file
Created May 15, 2013 09:43
Get path for storing internet file to local
// Get a temp file path
[NSTemporaryDirectory() stringByAppendingPathComponent:@"myapptempdirectory.jpg"]);
// To get the filename from the url
[@"http://stackoverflow.com/questions/1098957/objective-c-extract-filename-from-path-string.jpg" lastPathComponent];
@hlxwell
hlxwell / new_gist_file
Created May 19, 2013 07:43
speex to google speech recognition
curl --data-binary @sound.spx --header 'Content-type: audio/x-speex-with-header-byte; rate=16000' 'https://www.google.com/speech-api/v1/recognize?client=chromium&lang=en-US&maxresults=2'
@hlxwell
hlxwell / sort_xcode_project.sh
Created May 21, 2013 03:48
Sort xcode project files, so could be helpful for the teamwork.
#!/usr/bin/perl -w
# Copyright (C) 2007, 2008, 2009, 2010 Apple Inc. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
require "rubygems"
require "rspec"
class String
def syllable
# bl|qu|ng|ch|rt|
consonants = "bcdfghjklmnpqrstvwxzh"
vowels = "aeiouy"
word = self.downcase
parts = word.split(/(?=ly)/)
@hlxwell
hlxwell / sign.sh
Created June 18, 2013 15:13
Sign mac app file
codesign -f -v -s "Mac Developer: lixing he (6EAVUH8752)" ./Sparkle.framework/Versions/A/Resources/relaunch