Skip to content

Instantly share code, notes, and snippets.

View shakemno's full-sized avatar

Manolis Pahlke shakemno

View GitHub Profile
//:
//: UIView Animation Syntax Sugar
//:
//: Created by Andyy Hope on 18/08/2016.
//: Twitter: @andyyhope
//: Medium: Andyy Hope, https://medium.com/@AndyyHope
import UIKit
extension UIView {
import Dispatch
private var throttleWorkItems = [AnyHashable: DispatchWorkItem]()
private var lastDebounceCallTimes = [AnyHashable: DispatchTime]()
private let nilContext: AnyHashable = arc4random()
public extension DispatchQueue {
/**
- parameters:
- deadline: The timespan to delay a closure execution
@shakemno
shakemno / encrypt_xor1.swift
Created November 1, 2018 11:10 — forked from alskipp/encrypt_xor1.swift
Swift encrypt/decrypt string using XOR
import Foundation
extension Character {
func utf8() -> UInt8 {
let utf8 = String(self).utf8
return utf8[utf8.startIndex]
}
}
func encrypt(c:Character, key:Character) -> String {
@shakemno
shakemno / SKStoreReviewDummyClass.m
Created December 6, 2018 08:56 — forked from username0x0a/SKStoreReviewDummyClass.m
Dummy class easing detection whether the native StoreKit in-app Review alert has been fired or not. Useful as a callback when firing the limited system rating alert.
@interface SKStoreReviewDummyClass : NSObject @end
@implementation SKStoreReviewDummyClass
+ (void)load
{
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
Class class = [self class];
# 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 / 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 January 31, 2023 16:50 — 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",