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):
@TonnyXu
TonnyXu / UITableView_SeparatorLine.md
Created May 10, 2012 13:21
set UITableView.separatorLine to 2px and with different colors each pixel

Question

How to implement a UITableView with a separator line like this:

doubly separator line

Usually, you can only set the separatorLine property of a UITableView with to single line or single line etched. Sometimes, it is not enough. So, how to implement a separator line like this?

Answer

@TonnyXu
TonnyXu / Description.md
Created February 3, 2012 10:03
Make the UITableView with group style to round the image.

The point is, the roundCorner is draw by a subview of UITableViewCell, and mean while, it's not a public class, there is no way you can get layer.cornerRadius from any view. So we need to resolve this problem by ourselves.

There are 2 cases.

  1. There is only one cell.

    This case is ease, just use cell.contentView.layer.cornerRadius and cell.contentView.layer.masksToBounds to make it work.

  2. There are more than one cell.

@TonnyXu
TonnyXu / iOSUnitTestBundlePath.m
Created January 29, 2012 08:49
Use bundleForClass to get the unit test bundle's path
/*
This tips is extremely useful when you test your CoreData app in Unit Test.
*/
// iOS app is an executable bundle, means the `main` method is
// included inside app bundle, so `mainBundle` returns the app bundle
//
// See doc at https://developer.apple.com/library/ios/#documentation/Cocoa/Reference/Foundation/Classes/NSBundle_Class/Reference/Reference.html#//apple_ref/doc/uid/TP40003624
NSBundle *appBundle = [NSBundle mainBundle];
@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 / NSOrderSet+Insert.md
Created February 1, 2012 09:59
NSOrderedSet does not work well on insert

Usually, we generate an entity class with Editor->Create NSManagedOBject Subclass... For example we created a subclass of NSManagedObject

Xcode generates the .h file like this:

@interface MyEntity : NSManagedObject

@property (nonatomic, retain) NSOrderedSet manySubs;

//... some methods generated by Xcode

@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

//
// 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 / 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";