Skip to content

Instantly share code, notes, and snippets.

View shakemno's full-sized avatar

Manolis Pahlke shakemno

View GitHub Profile
@shakemno
shakemno / GetConstraintByIdentifier.swift
Created January 31, 2019 13:41
Get a constraint by identifier - without the need of using a property
// add .identifier
let centerXConstraint = view.centerXAnchor.constraint(equalTo: centerXAnchor, constant: 0)
centerXConstraint.identifier = "IdentifierName"
// get constraint
let constraintByIdentifier = view.constraints.filter ({ $0.identifier == "IdentifierName" }).first
# taken from http://www.piware.de/2011/01/creating-an-https-server-in-python/
# generate server.xml with the following command:
# openssl req -new -x509 -keyout server.pem -out server.pem -days 365 -nodes
# run as follows:
# python simple-https-server.py
# then in your browser, visit:
# https://localhost:4443
import BaseHTTPServer, SimpleHTTPServer
import ssl
@shakemno
shakemno / TimingFunction.swift
Created February 21, 2019 15:50 — forked from naoyashiga/TimingFunction.swift
TimingFunction.swift
import Foundation
enum timingFunction{
case Linear,EaseIn,EaseOut,EaseInOut,
Spring,
EaseInSine,EaseOutSine,EaseInOutSine,
EaseInQuad,EaseOutQuad,EaseInOutQuad,
EaseInCubic,EaseOutCubic,EaseInOutCubic,
EaseInQuart,EaseOutQuart,EaseInOutQuart,
EaseInQuint,EaseOutQuint,EaseInOutQuint,
import Foundation
import UIKit
struct ViewStyle<T> {
let style: (T) -> Void
}
let filled = ViewStyle<UIButton> {
$0.setTitleColor(.white, for: .normal)
$0.backgroundColor = .red
@shakemno
shakemno / fix_apple_coretelephony_debug.sh
Created March 25, 2019 20:43
Fix xcode coretelephony + firebase bug
xcrun simctl spawn booted log config --mode "level:off" --subsystem com.apple.CoreTelephony
# source: https://github.com/aws-amplify/aws-sdk-ios/issues/1251#issuecomment-471866504
@shakemno
shakemno / UIView+FindSuperview.swift
Last active May 1, 2019 13:56 — forked from nkukushkin/UIView+FindSuperview.swift
Recursive search for the first superview matching certain criteria.
extension UIView {
func firstSuperview<T>(where predicate: (T) -> Bool) -> T? where T: UIView {
if let superview = superview as? T, predicate(superview) {
return superview
}
return superview?.firstSuperview(where: predicate)
}
}
// view.firstSuperview(where: { (view: UITableView) in view.isEditing })
@shakemno
shakemno / UIColor+HumanEyePleasing.swift
Last active May 27, 2026 13:28 — forked from klein-artur/complementaryColor.swift
UIColor + HumanEyePleasing - contrasting color extension (complementary or perceptive luminance)
extension UIColor {
// get a complementary color to this color
// https://gist.github.com/klein-artur/025a0fa4f167a648d9ea
var complementary: UIColor {
let ciColor = CIColor(color: self)
// get the current values and make the difference from white:
let compRed: CGFloat = 1.0 - ciColor.red
@shakemno
shakemno / randomWord.swift
Created May 1, 2019 18:24 — forked from emersonbroga/randomWord.swift
Swift Random Word Generator
//Inspired by: http://planetozh.com/blog/2012/10/generate-random-pronouceable-words/
func randomWord(wordLength: Int = 6) -> String {
let kCons = 1
let kVows = 2
var cons: [String] = [
// single consonants. Beware of Q, it"s often awkward in words
"b", "c", "d", "f", "g", "h", "j", "k", "l", "m",
"n", "p", "r", "s", "t", "v", "w", "x", "z",
@shakemno
shakemno / Fireworks.swift
Created May 2, 2019 19:31 — forked from victorchee/Fireworks.swift
Fireworks effect by emitter.
let emitterLayer = CAEmitterLayer()
emitterLayer.frame = navigationView.bounds
emitterLayer.renderMode = .additive
emitterLayer.emitterMode = .outline
emitterLayer.emitterShape = .line
emitterLayer.emitterSize = CGSize(width: 50, height: 0)
emitterLayer.emitterPosition = CGPoint(x: navigationView.bounds.width / 2, y: navigationView.bounds.height)
emitterLayer.velocity = 1
emitterLayer.seed = (arc4random() % 100) + 1
navigationView.layer.insertSublayer(emitterLayer, at: 0)
@shakemno
shakemno / introrx.md
Created July 4, 2019 22:15 — forked from staltz/introrx.md
The introduction to Reactive Programming you've been missing