Skip to content

Instantly share code, notes, and snippets.

@TonnyXu
TonnyXu / UIKit_System_Notifications.h
Created January 18, 2011 01:37
All the notifications predefined by UIKit framework. Apple should provide this but they don't. So, take it if you need it.
// UIApplication.h
UIApplicationDidEnterBackgroundNotification __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_4_0);
UIApplicationWillEnterForegroundNotification __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_4_0);
UIApplicationDidFinishLaunchingNotification;
UIApplicationDidBecomeActiveNotification;
UIApplicationWillResignActiveNotification;
UIApplicationDidReceiveMemoryWarningNotification;
UIApplicationWillTerminateNotification;
UIApplicationSignificantTimeChangeNotification;
UIApplicationWillChangeStatusBarOrientationNotification; // userInfo contains NSNumber with new orientation
#include <iostream>
int main (int argc, char * const argv[]) {
int i = 6;
std::cout << i++ << std::endl;
int j = i++;
std::cout << j << std::endl;
int p = 7;
std::cout << ++p << std::endl;
#include <iostream>
int main (int argc, char * const argv[]) {
int i = 1;
int j = i << 4;
std::cout << j << std::endl;
return 0;
}
#include <iostream>
int main (int argc, char * const argv[]) {
int i = 5;
int *p = &i;
++*p;
std::cout << i << std::endl;
return 0;
}
#include <iostream>
int main (int argc, char * const argv[]) {
int a[] = {3,2,1,0};
int *pa = a;
std::cout << pa++ << std::endl;
return 0;
}
public class Stack {
private Object[] elements;
private int size = 0;
public Stack(int initialCapacity) {
this.elements = new Object[initialCapacity];
}
public void push(Object e) {
ensureCapacity();
@TonnyXu
TonnyXu / gist:1131908
Created August 8, 2011 15:01
NSIndexPath is uniqued and shared.
#define myIndexPath [NSIndexPath indexPathForRow:2 inSection:1]
NSAssert(myIndexPath == [NSIndexPath indexPathForRow:2 inSection:1], @"they should be the same object");
// omitted code from UITableView -cellForRowAtIndexPath:
if (myIndexPath == systemIndexPath){
// my cell, show my contents
}
@TonnyXu
TonnyXu / countLines.sh
Created August 29, 2011 06:05
Count lines of source code files
wc -l `find . -type f \( -name "*.h" -or -name "*.m" \)`
@TonnyXu
TonnyXu / CountLines2.sh
Created August 29, 2011 06:42
To Handle spaces in file name.
find . -type f \( -name '*.xib' -or -name "*.h" -or -name "*.m" \) -exec awk '{print NR}' {} +|tail -1
@TonnyXu
TonnyXu / .bashrc
Created September 5, 2011 14:09
Colorful Bash Shell Prompt
# NOTE: all the color mark must be surrounded with \[\] to avoid a wrong line wrapping calculation.
export PS1="\[\e[35;40m\]\u\[\e[0m\]@\[\e[36;40m\]\h\[\e[0m\]:\[\e[37;40m\]\W\[\e[0m\] \t \[\e[36;40m\](\j) <\!>\[\e[0m\]\n\[\e[35;40m\]\$\[\e[0m\] "