Skip to content

Instantly share code, notes, and snippets.

View thexande's full-sized avatar

Alexander Murphy thexande

  • Denver, CO, USA, Planet Earth
View GitHub Profile
@vhart
vhart / UIColorFromHex.swift
Last active January 6, 2017 03:00
UIColor from hex
extension UIColor {
convenience init? (fromHex hex: String) {
let hexPattern = try! NSRegularExpression(pattern: "^[0-9a-fA-F]{6}$",
options: [.anchorsMatchLines])
let range = NSRange(location: 0, length: hex.characters.count)
guard hexPattern.matches(in: hex,
options: [],
range: range).count == 1
else { return nil }
@vyder
vyder / rbenv-in-xcode-build-script.md
Created October 17, 2016 09:24
Using rbenv in an XCode 'Run Script Phase'

If anybody stumbles across this from Google, I found that the simplest thing to do was:

Have devs install rbenv on their machines, and add ~/.rbenv/shims to the PATH in the XCode build script like:

export PATH=~/.rbenv/shims:$PATH
# Exec rest of your script
# ...

@aniltv06
aniltv06 / Slider.swift
Created September 29, 2016 09:38
Programatically adding UISlider - swift 3
override func viewDidLoad() {
super.viewDidLoad()
let slider = UISlider(frame:CGRectMake(70, 550, 280, 20))
slider.minimumValue = 0
slider.maximumValue = 100
slider.continuous = true
slider.tintColor = UIColor.redColor()
slider.value = 50
slider.addTarget(self, action: #selector(ViewController.sliderValueDidChange(_:)), forControlEvents: .ValueChanged)
self.view.addSubview(slider)
@thexande
thexande / mov2gif.sh
Last active September 18, 2016 22:33
# first run brew install ffmpeg && brew install imagemagick
# next, add lines 6 - 9 into your .zshrc or .bashrc file, depending on your shell you use ( zsh or bash )
# restart your terminal!
# then call like "movtogif in.mov out.gif"
movtogif(){
ffmpeg -i "$1" -vf scale=800:-1 -r 10 -f image2pipe -vcodec ppm - |\
convert -delay 5 -layers Optimize -loop 0 - "$2"
}
@kristofer
kristofer / KeychainPasscodeRepository.swift
Created August 3, 2016 11:55
KeychainPasscodeRepository - a simple example of a ios keychain based repository for https://github.com/yankodimitrov/SwiftPasscodeLock
//
// KeychainPasscodeRepository.swift
// PasscodeLock
// a simple example of a keychain based repository
// https://github.com/yankodimitrov/SwiftPasscodeLock
// uses this fine work for easy access to Keychain
// https://cocoapods.org/pods/KeychainAccess
// written by https://github.com/kristofer
@jarretmoses
jarretmoses / React Native Clear Cache
Last active April 23, 2025 11:20
Clearing the Cache of your React Native Project
RN < 0.50 - watchman watch-del-all && rm -rf $TMPDIR/react-* && rm -rf node_modules/ && npm cache clean && npm install && npm start -- --reset-cache
RN >= 0.50 - watchman watch-del-all && rm -rf $TMPDIR/react-native-packager-cache-* && rm -rf $TMPDIR/metro-bundler-cache-* && rm -rf node_modules/ && npm cache clean && npm install && npm start -- --reset-cache
RN >= 0.63 - watchman watch-del-all && rm -rf node_modules && npm install && rm -rf /tmp/metro-* && npm run start --reset-cache
npm >= 5 - watchman watch-del-all && rm -rf $TMPDIR/react-* && rm -rf node_modules/ && npm cache verify && npm install && npm start -- --reset-cache
Windows - del %appdata%\Temp\react-native-* & cd android & gradlew clean & cd .. & del node_modules/ & npm cache clean --force & npm install & npm start -- --reset-cache
@delputnam
delputnam / TextColor.swift
Created June 25, 2016 12:27
Determine if a UIColor is light or dark
// Returns black if the given background color is light or white if the given color is dark
func textColor(bgColor: UIColor) -> UIColor {
var r: CGFloat = 0.0
var g: CGFloat = 0.0
var b: CGFloat = 0.0
var a: CGFloat = 0.0
var brightness: CGFloat = 0.0
bgColor.getRed(&r, green: &g, blue: &b, alpha: &a)
@meteochu
meteochu / UIFont++.swift
Last active February 7, 2017 19:55
UIFont extension for UIFontTextStyle and UIFontWeight
import UIKit
extension UIFont {
enum TextStyle: String {
case title1
case title2
case title3
case headline
/// A simple hello world view that uses Auto Layout.
public class HelloWorldAutoLayout: UIView {
private lazy var imageView: UIImageView = {
let imageView = UIImageView()
imageView.translatesAutoresizingMaskIntoConstraints = false
imageView.setContentHuggingPriority(UILayoutPriorityRequired, forAxis: .Vertical)
imageView.setContentHuggingPriority(UILayoutPriorityRequired, forAxis: .Horizontal)
imageView.setContentCompressionResistancePriority(UILayoutPriorityRequired, forAxis: .Vertical)
imageView.setContentCompressionResistancePriority(UILayoutPriorityRequired, forAxis: .Horizontal)
@stinger
stinger / Swift3Dates.swift
Last active May 21, 2018 02:04
Swift 3: Working with dates
//: # Swift 3: Working with dates
import Foundation
let date = Date()
let myLocale = Locale(identifier: "bg_BG")
//: ### Setting an application-wide `TimeZone`
//: Notice how we use if-let in case the abbreviation is wrong. It will fallback to the default timezone in that case.
if let myTimezone = TimeZone(abbreviation: "EEST") {
print("\(myTimezone.identifier)")