Skip to content

Instantly share code, notes, and snippets.

Tonny Xu TonnyXu

Block or report user

Report or block TonnyXu

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@TonnyXu
TonnyXu / test.py
Created May 11, 2017
Workable safari webdriver script for selenium
View test.py
"""
automation based on selenium webdriver with safari native support
"""
from selenium.webdriver.common.by 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
end
table = ["AAAAAA", "AABABB", "AABBAB", "AABBBA", "ABAABB", "ABBAAB", "ABBBAA", "ABABAB", "ABABBA", "ABBABA"]
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
TonnyXu / reenablePN.md
Created Sep 7, 2012
Reenable Push Notification when user disabled it on the first time confirmation alert is shown
View reenablePN.md

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
TonnyXu / kvcDemo.md
Created Aug 24, 2012
using KVC on collection objects like NSArray and NSDictionary.
View kvcDemo.md

KVCを使えば、このようなコードが自動的に値を計算してくれる。

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

AppleのDocを見る

@max, @min, @sum, @avg

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

@TonnyXu
TonnyXu / list.md
Created Aug 22, 2012
Supported NSLocal Identifier and NSTimeZone Name
View list.md

目的

このようなコードを使えるようにする:

    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
TonnyXu / gcdSemaphor.md
Created Aug 7, 2012
Using GCD to let a thread/queue wait, an alternative way for `sleep(n)`
View gcdSemaphor.md

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:@"http://www.google.com"]];
@TonnyXu
TonnyXu / RVi.md
Created Aug 3, 2012
About RVI(Remote Virtual Interface)
View RVi.md

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
TonnyXu / NSOperation.md
Created Aug 2, 2012
`-init` method is called from the caller's thread | CoreData Pitfall
View NSOperation.md

Refresh: How to use NSOperation

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

Create your own NSOperation subclass

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

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

The answer is: YES

How?

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

You can’t perform that action at this time.