This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Pretty-printing JSON and XML on Mac OSX | |
Like my colleagues at Avisi I’m an avid OSX user. One of the reasons I like OSX is it gives you the power of Unix right under your fingertips while still providing a nice user interface. | |
Now suppose you’re working on RESTful services and you need to verify or debug some JSON output. Digging through an unformatted JSON string can be a real pain. To make a JSON string human readable open up the Terminal and type: | |
cat unformatted.json | python -m json.tool > formatted.json | |
This will pretty-print the contents of “unformatted.json” to a new file called “formatted.json”. For this to work you need to have at least Python 2.6 installed. Which is the case when your running Snow Leopard or higher. | |
The above command assumes you have a file containing the JSON content. When you’re debugging it’s more likely you copied a JSON string to your clipboard from a (remote) log file. To pretty-print the JSON content on your clipboard type: | |
pbpaste | python -m json.tool > formatted.json | |
L |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// http://stackoverflow.com/a/18886352/1107242 | |
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch | |
{ | |
if (touch.view != _mySuperView) { // accept only touchs on superview, not accept touchs on subviews | |
return NO; | |
} | |
return YES; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 1. Xcode->preferences->Components下载后存在哪?(runtime 和 document) | |
// /Library/Developer/CoreSimulator/Profiles/Runtimes | |
// ~/Library/Developer/CoreSimulator/Devices/ | |
// ~/Library/Developer/Shared/Documentation/DocSets/ | |
// 2. 虚拟设备的配置文件和安装的app,建议用Xcode的Devices工具管理,也可以用 xcrun simctl 命令管理 | |
// ~/Library/Developer/CoreSimulator/Devices/ | |
// 3. 移动设备接入电脑后,会自动生成这些。删除后下次会重建————没必要删除,除非你确认这个设备再不会使用了 | |
// ~/Library/Developer/Xcode/iOS\ DeviceSupport/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
override func viewDidLoad() { | |
super.viewDidLoad() | |
// Uncomment the following line to preserve selection between presentations. | |
// self.clearsSelectionOnViewWillAppear = false | |
// Uncomment the following line to display an Edit button in the navigation bar for this view controller. | |
// self.navigationItem.rightBarButtonItem = self.editButtonItem | |
let g = ESGlobal.sharedInstance() | |
segmentedControl.selectedSegmentIndex = g.networkType() | |
textView0.text = g.debugInfo().description |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Might be you will need to snapshot a particular view into an image. Previously we do like this: | |
// #import <QuartzCore/QuartzCore.h> | |
UIGraphicsBeginImageContextWithOptions(view.bounds.size, NO, 0); | |
[view.layer renderInContext:UIGraphicsGetCurrentContext()]; | |
UIImage *copied = UIGraphicsGetImageFromCurrentImageContext(); | |
UIGraphicsEndImageContext(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
When edit your source code file, tap cmd+f, and click the mangifier icon, then you can edit Find Options, where "Wrap Around" means whether you will "Start over from the top of the document when no match is found". |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 监听窗口事件 | |
// NSNotification.Name.UIWindowDidBecomeHidden = "UIWindowDidBecomeHiddenNotification" | |
NotificationCenter.default.addObserver(forName: NSNotification.Name.UIWindowDidResignKey, object: nil, queue: .main) { (notice) in | |
guard let w = notice.object as? UIWindow else { return } | |
if w == self.window { | |
lockDeviceInterfaceToLandscape = true | |
app.statusBarOrientation = .landscapeRight | |
} else { | |
lockDeviceInterfaceToLandscape = false | |
app.statusBarOrientation = .portrait |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ProgressSlider: UISlider { | |
override func thumbRect(forBounds bounds: CGRect, trackRect rect: CGRect, value: Float) -> CGRect { | |
let max = maximumValue == 0 ? 1.0 : maximumValue | |
let side: CGFloat = 8 | |
let centerX: CGFloat = rect.width * CGFloat(value / max) | |
let r = CGRect(x: ceil(centerX) - side / 2, y: rect.midY - side / 2, width: side, height: side) | |
return r | |
} | |
override func layoutSubviews() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protocol MakeSelf { | |
init() | |
} | |
class MS: MakeSelf { | |
static let shared = MS() | |
required init() { | |
// | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protocol EnumCollection : Hashable {} | |
extension EnumCollection { | |
static func cases() -> AnySequence<Self> { | |
typealias S = Self | |
return AnySequence { () -> AnyIterator<S> in | |
var raw = 0 | |
return AnyIterator { | |
let current : Self = withUnsafePointer(to: &raw) { $0.withMemoryRebound(to: S.self, capacity: 1) { $0.pointee } } | |
guard current.hashValue == raw else { return nil } | |
raw += 1 |