Skip to content

Instantly share code, notes, and snippets.

View mwrites's full-sized avatar
🔧

Supermercat mwrites

🔧
View GitHub Profile
@mwrites
mwrites / gist:1565a1f592192b084b9133a7f0eb0be3
Last active January 30, 2017 06:25
Open workspace or xcodeproj
#!/bin/bash
open -a "/Applications/Xcode.app" *.xcworkspace &>/dev/null || open -a "/Applications/Xcode.app" *xcodeproj
@mwrites
mwrites / UIViewController+ModalHelpers.swift
Last active February 1, 2017 17:46
dismiss two modal without showing first modal background
extension UIViewController {
func dismissModal(animated: Bool = true, completion: (()->Void)? = nil) {
if let snapshot = UIApplication.shared.delegate?.window??.snapshotView(afterScreenUpdates: false) {
self.presentedViewController?.view.addSubview(snapshot)
}
self.dismiss(animated: animated, completion: completion)
}
}
@mwrites
mwrites / swift
Created February 13, 2017 09:02
Semi self-sizing CollectionViewCell with autolayout
var COLLECTIONVIEWHEIGHT: CGFloat!
var LINESPACING: CGFloat!
var cachedHeights = [String:CGFloat]()
class WordTileCollectionViewCell: UICollectionViewCell {
@IBOutlet weak var wordLabel: UILabel!
@mwrites
mwrites / JsonDic
Created February 15, 2017 06:21
JsonDic parsing helper
struct JsonDic {
let dic : [String:AnyObject]
func integer(key: String) throws -> Int {
guard let s = dic[key] as? Int else { throw ResourceError.parseWrongType(key) }
return s
}
func string(key: String) throws -> String {
guard let s = dic[key] as? String else { throw ResourceError.parseWrongType(key) }
@mwrites
mwrites / dictionaryMerge.swift
Last active February 16, 2017 07:11
Merge dictionaries
mutating func merge(with dictionary: Dictionary) {
dictionary.forEach { updateValue($1, forKey: $0) }
}
func merged(with dictionary: Dictionary) -> Dictionary {
var dict = self
dict.merge(with: dictionary)
return dict
}
@mwrites
mwrites / snippets.cson
Created March 15, 2017 06:32
Atom snippets
'.source.js':
'Create page':
'prefix': 'createpage'
'body' : 'var page = require(\'webpage\').create();'
'Open page':
'prefix': 'openpage'
'body' : """
page.open(url, function(status) {
$1
});
@mwrites
mwrites / gist:51ecca480fb8ddc4fc6ed9835d45cb44
Created July 18, 2017 12:04 — forked from krzysztofzablocki/gist:4396302
Set symbol breakpoint on objc_msgSend then setup this debug command to log all methods called in iOS Simulator. If you want to do device debugging change esp+4 register to r0, esp+8 to r1 Found long ago somewhere on stackoverflow.
expr -- (void)printf("[%s, %s]\n",(char *) object_getClassName(*(long*)($esp+4)), (char *) *(long *)($esp+8) )
@mwrites
mwrites / ArrayPack.swift
Last active July 22, 2017 06:32
extend array of custom type
extension Array where Element:PackProtocol {
static func build(from json: [String:Any]) -> PackList {
let jsonPacks = json["packs"] as! [[String:Any]]
let packs = jsonPacks.flatMap { Pack.init(from: $0) }
return packs
}
}
(lldb) expr -l Swift -- import UIKit
(lldb) expr -l Swift -- let $pin = unsafeBitCast(0x7df67c50, to: MKPinAnnotationView.self)
(lldb) expr -l Swift -- print($pin.alpha)