Skip to content

Instantly share code, notes, and snippets.

@nanoxd
nanoxd / ScreenShottable.swift
Last active September 22, 2018 16:45
[ScreenShottable] Screenshot a view using UIGraphicsImageRenderer #swift #uikit
protocol Screenshottable {
func screenshot() -> UIImage?
}
extension UIView: Screenshottable {
func screenshot() -> UIImage? {
let renderer = UIGraphicsImageRenderer(bounds: bounds)
return renderer.image { _ in
drawHierarchy(in: self.bounds, afterScreenUpdates: false)
@nanoxd
nanoxd / UIImage+RenderMode.swift
Last active September 22, 2018 16:45
[UIImage+RenderMode] Easily use a different rendering mode on an UIImage #uikit #swift
public extension UIImage {
public var original: UIImage { return withRenderingMode(.alwaysOriginal) }
public var template: UIImage { return withRenderingMode(.alwaysTemplate) }
}
@nanoxd
nanoxd / Optional+KeyPathMap.swift
Last active September 22, 2018 16:46
[Optional+KeyPathMap] Maps an optional value to a property on the object using a keyPath. #swift
extension Optional {
public func map<T>(_ keyPath: KeyPath<Wrapped, T>) -> T? {
return map({ $0[keyPath: keyPath] })
}
}
@nanoxd
nanoxd / KeyPath+Closures.swift
Last active December 10, 2018 12:20
Key Path for Closures
prefix operator ^
prefix func ^<Root, Value>(keyPath: KeyPath<Root, Value>) -> (Root) -> Value {
return { $0[keyPath: keyPath] }
}
@nanoxd
nanoxd / ch-init
Created June 27, 2018 19:59
Clubhouse-Git integration
#!/usr/bin/env sh
#/ Usage: ch-init 123
# Initializes the current branch to a ticket
if [ $# = "0" ]; then
printf 'usage: ch-init <ticket>\n'
exit 1
fi
TICKET="$@"
@nanoxd
nanoxd / UIButton+Rx.swift
Last active September 22, 2018 16:47
[UIButton+IsCheckedRx] Adds checked behavior to UIButton #uikit #swift
extension Reactive where Base: UIButton {
/// Alternated with button taps to provide
/// a checkbox behavior by `UIButton`
var checked: ControlProperty<Bool> {
let button = self.base
let source: Observable<Bool> = self.tap
.map {[weak button] in
guard let state = button?.isSelected else {
return false
}
@nanoxd
nanoxd / mobile_ci.md
Last active February 15, 2018 14:29
Mobile CI Tryouts

App Center

Pros

  • Easy setup
  • Multitude of different tools included by default
  • Team Management
  • Webhooks
  • Extensible via clones
  • Fast start on builds
@nanoxd
nanoxd / git-sweep
Last active April 28, 2017 20:41
Clean up branches
#!/bin/bash
# git-sweep
# Cleans up branches on Origin and verifies that they have already been merged
# USAGE: git sweep
# This must be run from master
git checkout master
# Update our list of remotes
git fetch
git remote prune origin
@nanoxd
nanoxd / wercker.yml
Last active March 2, 2017 18:05
Wercker with Yarn
box: node
build:
steps:
- script:
name: Setup Yarn Caching
code: export YARN_CACHE=$WERCKER_CACHE_DIR/yarn
- script:
name: Yarn Install
code: HOME=$YARN_CACHE yarn --no-progress
- script:

Keybase proof

I hereby claim:

  • I am nanoxd on github.
  • I am nanoxd (https://keybase.io/nanoxd) on keybase.
  • I have a public key ASCyQEMSeoe49Rf__mhySgR6vtqbCMGKgYPikQt0ZLLC9go

To claim this, I am signing this object: