Skip to content

Instantly share code, notes, and snippets.

@iamjason
iamjason / simulator_fullscreen.sh
Created October 26, 2018 19:18
Allow XCode + Simulator to share a split screen
defaults write com.apple.iphonesimulator AllowFullscreenMode -bool YES
@iamjason
iamjason / Date+FindPrevNextWeekday.swift
Created February 2, 2018 03:51
Extension that helps to find the week's previous/next weekday. e.g. if it's sunday, what was last monday's date?
/**
Extension that helps to find the week's previous/next weekday.
e.g. if it's sunday, what was last monday's date?
usage: Date().get(direction: .previous, dayName: .monday, considerToday: true)
*/
extension Date {
// weekday is in form 1...7
enum WeekDay: Int {
case sunday = 1, monday, tuesday, wednesday, thursday, friday, saturday
import UIKit
import RxCocoa
import RxSwift
// KEYBOARD STUFF
extension UIViewController {
func setupViewResizerOnKeyboardShown(bag:DisposeBag) {
NotificationCenter.default.rx
@iamjason
iamjason / String+HTMLToNSAttributedString.swift
Last active March 9, 2017 21:10
HTML to NSAttributedString
import UIKit
public extension String {
static let htmlBase = "<html><head><style type='text/css'> body { color: %COLOR%; } %STYLE% </style></head><body>%BODY%</body></html>"
static let cssBase = " h1 { font-family: 'GTWalsheimLight'; font-size: 34px; } h2 { font-family: 'GTWalsheimBold'; font-size: 24px; } h3 { font-family:'GTWalsheimLight'; font-size: 18px; } h4 { font-family:'GTWalsheimBold'; font-size: 14px; } h5 { font-family:'GTWalsheimBold'; font-size: 12px; } p { font-family: 'SourceSansPro-Regular'; font-size: 16px; } p.strong { font-family: 'SourceSansPro-Semibold'; font-size: 16px; }"
public func HTMLtoAttributedText(_ color:UIColor = UIColor.black, css:String = String.cssBase) -> NSAttributedString? {
@iamjason
iamjason / Fonts+Helper.swift
Last active May 24, 2017 05:29
Loading Custom Fonts - Swift 3
import UIKit
/// Load Fonts
///
/// Example Usage:
///
/// let fonts = ["SourceSansPro-Regular.otf", "GT-Walsheim-Regular.ttf"]
///
/// let loadedSuccessfuly = loadFonts(fonts)
///
@iamjason
iamjason / noah's ark.swift
Last active April 18, 2016 15:37
Noah's Ark w/ Swift 2 using immutable values
// Inspired by: https://gist.github.com/futurepaul/8b99d502006cf8a67a93
import UIKit
typealias 🐾 = String
let 🌍 = "🦃🕊🐶🐺🐱🐭🐹🐰🐸🐯🐨🐻🐷🐽🐮🐗🐵🐒🐴🐑🐘🐼🐧🐦🐤🐥🐣🐔🐍🐢🐛🐝🐜🐞🐌🐙🐚🐠🐟🐬🐳🐋🐄🐏🐀🐃🐅🐇🐉🐎🐐🐓🐕🐖🐁🐂🐲🐡🐊🐫🐪🐆🐈🐩"
let 🚢 = 🌍.characters
.map { (🚜) -> 🐾 in
return 🐾(🚜)
}
@iamjason
iamjason / ping-google
Created April 16, 2015 23:51
testing time warner's new router
➜ Maven git:(master) ✗ ping -c google.com
ping: invalid count of packets to transmit: `google.com'
➜ Maven git:(master) ✗ ping -c 10 google.com
PING google.com (74.125.226.9): 56 data bytes
64 bytes from 74.125.226.9: icmp_seq=0 ttl=52 time=13.532 ms
64 bytes from 74.125.226.9: icmp_seq=1 ttl=52 time=562.196 ms
64 bytes from 74.125.226.9: icmp_seq=2 ttl=52 time=11.785 ms
64 bytes from 74.125.226.9: icmp_seq=3 ttl=52 time=18.157 ms
64 bytes from 74.125.226.9: icmp_seq=4 ttl=52 time=12.873 ms
64 bytes from 74.125.226.9: icmp_seq=5 ttl=52 time=10.785 ms
@iamjason
iamjason / us-states-array
Created December 29, 2014 01:31
Swift US States Array
let state = [ "AK - Alaska",
"AL - Alabama",
"AR - Arkansas",
"AS - American Samoa",
"AZ - Arizona",
"CA - California",
"CO - Colorado",
"CT - Connecticut",
"DC - District of Columbia",
"DE - Delaware",
@iamjason
iamjason / JGCell.swift
Created December 16, 2014 20:39
Generic UITableViewCell Implementation (swift)
class JGCell : UITableViewCell {
override init(style: UITableViewCellStyle, reuseIdentifier: String!) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
setupViews()
}
required init(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
@iamjason
iamjason / gist:8457cf00a34e3cf0844c
Last active August 29, 2015 14:11
polygon rounded path + image mask
// Playground - noun: a place where people can play
import UIKit
import XCPlayground
class RoundedPolygonImageView : UIImageView {
let maskLayer = CAShapeLayer()
let borderLayer = CAShapeLayer()