Skip to content

Instantly share code, notes, and snippets.

View pofat's full-sized avatar

Pofat pofat

View GitHub Profile
@pofat
pofat / Sticker.json
Created August 6, 2017 15:43
Include all information to parse a sticker URL
{
"thumbnail_must_containt" : "mdCMN09Image"
}
@pofat
pofat / Wall Papers
Last active August 22, 2017 08:21
For wall papers URL pools (720x1280)
https://wallpaperscraft.com/image/cosmos_sun_eclipse_clouds_58244_720x1280.jpg,https://wallpaperscraft.com/image/mountains_nature_sky_river_beautiful_scenery_93460_720x1280.jpg
@pofat
pofat / Fastfile
Last active March 26, 2023 01:58
Shell script and Fastfile to build universal framework.
fastlane_version "2.50.1"
default_platform :ios
platform :ios do
before_all do
# ENV["SLACK_URL"] = "https://hooks.slack.com/services/..."
# cocoapods
end
extension Float {
var toInt32: Int32 {
// Directly bitwise copy and expressed as Int32
return Int32(bitPattern: self.bitPattern)
}
}
lef f1 = Float(338_556)
let f2 = f1 + f1.ulp
@pofat
pofat / UIView+Extension.swift
Created January 5, 2018 09:10
Better way of adding subviews at once.
/*
From: https://twitter.com/johnsundell/status/948513364015288320?utm_content=buffer67c28&utm_medium=social&utm_source=facebook.com&utm_campaign=buffer
*/
extension UIView {
func add(_ subviews: UIView...) {
subviews.forEach(addSubview)
}
}
@pofat
pofat / then.swift
Last active November 7, 2018 12:43
Better way to do initialization in Swift
// From https://github.com/devxoul/Then/blob/master/Sources/Then/Then.swift
// It's easy to move them into your codebase
import Foundation
public protocol Then {}
extension Then where Self: Any {
/// Makes it available to set properties with closures just after initializing.
///
@pofat
pofat / MapDidDrag.swift
Created December 11, 2018 14:40
How to detect the first drag after map is loaded
class MapViewController: UIViewController {
var isLoaded = false
}
extension MapViewController: MKMapViewDelegate {
func mapViewDidChangeVisibleRegion(_ mapView: MKMapView) {
if isLoaded {
mapDidDrag()
}
}
@pofat
pofat / MapDidDrag_RAC.swift
Last active December 11, 2018 14:47
Use RAC to detect first drag after the map is loaded
import ReactiveSwift
import Result
class MapViewController: UIViewController {
private let (didLoadSingal, didLoadObserver) = Signal<Bool, NoError>.pipe()
private let (didDragSignal, didDragObserver) = Signal<Bool, NoError>.pipe()
override func viewDidLoad() {
super.viewDidLoad()
@pofat
pofat / ocmock-cheatsheet.m
Created December 20, 2018 14:59 — forked from oks/ocmock-cheatsheet.m
OCMock cheatsheet
/*----------------------------------------------------*/
#pragma mark - XCTAsserts
/*----------------------------------------------------*/
XCTAssert(expression, format...);
XCTAssertTrue(expression, format...);
XCTAssertFalse(expression, format...);
XCTAssertEqual(expression1, expression2, format...);
XCTAssertNotEqual(expression1, expression2, format...);
XCTAssertNil(expression, format...);
@pofat
pofat / RxRequests.swift
Created May 4, 2019 15:26
Rx + Network Request
import Foundation
import RxSwift
enum HTTPMethod: String {
case POST, GET
}
// protocol of request, should define endpoint, http method, params and response type
protocol Request {
var path: String { get }