Skip to content

Instantly share code, notes, and snippets.

@TonnyXu
TonnyXu / test.py
Created May 11, 2017 09:12
Workable safari webdriver script for selenium
"""
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):
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
//
// 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 September 7, 2012 07:35
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
TonnyXu / kvcDemo.md
Created August 24, 2012 08:56
using KVC on collection objects like NSArray and NSDictionary.

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 August 22, 2012 11:58
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
TonnyXu / gcdSemaphor.md
Created August 7, 2012 06:23
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:@"http://www.google.com"]];
@TonnyXu
TonnyXu / RVi.md
Created August 3, 2012 07:49
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
TonnyXu / NSOperation.md
Created August 2, 2012 04:54
`-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
@end
@TonnyXu
TonnyXu / DebugNewiOSWithOldXcode.md
Created July 3, 2012 09:48
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

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