Skip to content

Instantly share code, notes, and snippets.

View BrandonShega's full-sized avatar

Brandon Shega BrandonShega

View GitHub Profile
@BrandonShega
BrandonShega / style.less
Last active September 4, 2015 18:03
Atom Vim Cursor Hack
atom-text-editor.vim-mode.normal-mode,
atom-text-editor.vim-mode.operator-pending-mode,
atom-text-editor.vim-mode.visual-mode
{
&, // only keep this if you want to see the cursor on non-focused tabs
&.is-focused {
&::shadow, // shadow-DOM enabled
& // shadow-DOM disabled
{
/* cursor color */
@BrandonShega
BrandonShega / ckpem.txt
Created April 14, 2016 16:15
Creating a ck.pem file
# Convert the .cer file into a .pem file:
$ openssl x509 -in aps_development.cer -inform der -out PushChatCert.pem
# Convert the private key’s .p12 file into a .pem file:
$ openssl pkcs12 -nocerts -in PushChatKey.p12 -out PushChatKey.pem
# Finally, combine the certificate and key into a single .pem file
$ cat PushChatCert.pem PushChatKey.pem > ck.pem
# At this point it’s a good idea to test whether the certificate works.
@BrandonShega
BrandonShega / playground.swift
Last active August 10, 2016 18:35
Hacker news
//: Playground - noun: a place where people can play
import UIKit
import XCPlayground
XCPlaygroundPage.currentPage.needsIndefiniteExecution = true
typealias JSONDict = [String:AnyObject]
/*
@BrandonShega
BrandonShega / InvertedView.swift
Last active July 15, 2016 20:01
Inverted View
//: Playground - noun: a place where people can play
import UIKit
import XCPlayground
func mask(viewToMask: UIView, maskRect: CGRect, invert: Bool = false) {
let maskLayer = CAShapeLayer()
let path = CGPathCreateMutable()
if (invert) {
CGPathAddRect(path, nil, viewToMask.bounds)
import UIKit
class WCCountingLabel: UILabel {
private var start: CGFloat = 0
private var end: CGFloat = 0
private var progress: NSTimeInterval = 0
private var lastUpdate: NSTimeInterval = 0
private var totalTime: NSTimeInterval = 0
private var easingRate: CGFloat = 0
@BrandonShega
BrandonShega / gaps.swift
Last active August 25, 2016 14:02
Binary Gaps
//: Playground - noun: a place where people can play
//A binary gap within a positive integer N is any maximal sequence of consecutive zeros that is surrounded by ones at both ends in the binary representation of N.
//
//For example, number 9 has binary representation 1001 and contains a binary gap of length 2. The number 529 has binary representation 1000010001 and contains two binary gaps: one of length 4 and one of length 3. The number 20 has binary representation 10100 and contains one binary gap of length 1. The number 15 has binary representation 1111 and has no binary gaps.
//
//Write a function:
//
//public func solution(N : Int) -> Int
//that, given a positive integer N, returns the length of its longest binary gap. The function should return 0 if N doesn't contain a binary gap.
@BrandonShega
BrandonShega / RelativeTime.swift
Last active September 11, 2019 02:12
Relative Time
extension NSDate {
var relativeTime: String {
let calendar = NSCalendar.currentCalendar()
let components = calendar.components([.Second, .Minute, .Hour, .Day, .Month, .Year], fromDate: self, toDate: NSDate(), options: [])
if components.year > 0 {
if components.year < 2 {
return "Last year"
} else {
@BrandonShega
BrandonShega / MyViewController.swift
Created October 19, 2016 13:57
Table View Insets
import UIKit
import PlaygroundSupport
class MyViewController: UIViewController {
let tableView: UITableView
init() {
tableView = UITableView()
super.init(nibName: nil, bundle: nil)
@BrandonShega
BrandonShega / ViewController.swift
Created October 19, 2016 14:31
CollectionViewWithInsets
import UIKit
import PlaygroundSupport
class MyViewController: UIViewController {
let collectionView: UICollectionView
let flowLayout: UICollectionViewFlowLayout
init() {
flowLayout = UICollectionViewFlowLayout()
@BrandonShega
BrandonShega / viewController.swift
Created November 2, 2016 19:23
Collection View In Code
//: Playground - noun: a place where people can play
import UIKit
import PlaygroundSupport
class MyViewController: UIViewController {
let collectionView: UICollectionView
let flowLayout: UICollectionViewFlowLayout