Skip to content

Instantly share code, notes, and snippets.


Tonny Xu TonnyXu

View GitHub Profile
TonnyXu /
Created May 11, 2017
Workable safari webdriver script for selenium
automation based on selenium webdriver with safari native support
from import By
from selenium import webdriver
import unittest, time
class WebKitFeatureStatusTest(unittest.TestCase):
View gist:7f7f3b15a468811df207
def genFontStr13(str)
if (str =~ /^\d{13}$/).nil? then
return nil
first = str[0,1]
first6 = str[1,6]
last6 = str[7,6]
table2 = table[first.to_i]
result = first
View output.txt
// main.m
// NSStringHash
// Created by Tonny Xu on 2/10/13.
// Copyright (c) 2013 Tonny Xu. All rights reserved.
#import <Foundation/Foundation.h>
TonnyXu /
Created Sep 7, 2012
Reenable Push Notification when user disabled it on the first time confirmation alert is shown

Q:Can we reenable Push Notification after we disabled it at the first time?

A: YES, we can

Q: How?

  1. Delete the app.
  2. Wait for at least one day.

See reference:

TonnyXu /
Created Aug 24, 2012
using KVC on collection objects like NSArray and NSDictionary.


KVC with special keyPath is really powerful for collection objects like NSArray and NSDictionary and NSSet


@max, @min, @sum, @avg

Sample 1 : One of the element in the array does not contain height property

TonnyXu /
Created Aug 22, 2012
Supported NSLocal Identifier and NSTimeZone Name



    yyyyMMdd_HHmmss_dfObj = [[NSDateFormatter alloc] init];
    yyyyMMdd_HHmmss_dfObj.formatterBehavior = NSDateFormatterBehavior10_4;
    yyyyMMdd_HHmmss_dfObj.timeZone = [NSTimeZone timeZoneWithName:@"Asia/Tokyo"];
    yyyyMMdd_HHmmss_dfObj.calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
    yyyyMMdd_HHmmss_dfObj.locale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US"];
    yyyyMMdd_HHmmss_dfObj.dateFormat = @"yyyy-MM-dd HH:mm:ss";
TonnyXu /
Created Aug 7, 2012
Using GCD to let a thread/queue wait, an alternative way for `sleep(n)`

Before GCD

Almost the only option for us is sleep(n) (if you are familiar with SIGNAL, you can also use it). We are familiar with it, so let's pass it.

After GCD

There is resource called semaphore, use it can make your code more robust and more efficient.

  NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:@""]];
TonnyXu /
Created Aug 3, 2012
About RVI(Remote Virtual Interface)

What is RVI?

RVI = Remote Virtual Interface

What RVI can do?

Using RVI, you can capture network packages in iOS using any normal package capturing tools like tcpdump etc.

Wire your rvi to Mac

TonnyXu /
Created Aug 2, 2012
`-init` method is called from the caller's thread | CoreData Pitfall

Refresh: How to use NSOperation

Using NSOperation is easy, typically, it is used as below:

Create your own NSOperation subclass

@interface MyOperation : NSOperation
TonnyXu /
Created Jul 3, 2012
How to debug on a device with new iOS version with an old Xcode

Q: Is it possible to debug on a device with new iOS version with an old Xcode

The answer is: YES


It's not as simple as plug your device and go. Before we start to learn how, we need to understand something.

Understand the relationship between Xcode and iOS device