Skip to content

Instantly share code, notes, and snippets.

View atomkirk's full-sized avatar

Adam Kirk atomkirk

View GitHub Profile
@atomkirk
atomkirk / kill!!!!.md
Created June 10, 2015 17:41
My favorite way to kill a process with a name

PID=$(ps aux | grep -e 'vagrant' | grep -v grep | awk '{print $2}') && kill -s 9 $PID 2> /dev/null

//
// Created by Adam Kirk on 6/22/15.
//
import UIKit
extension UIView {
var x: CGFloat {
get {
//
// Created by Adam Kirk on 6/22/15.
//
import UIKit
extension UIScrollView {
var contentOffsetX: CGFloat {
get {
//
// Q.swift
// Created by Adam Kirk on 6/6/15.
//
import Foundation
public typealias QBlock = () -> Void
func serialQueueWithName(name: String) -> NSOperationQueue {
@atomkirk
atomkirk / Promise.swift
Created June 30, 2015 01:01
Simple Promise implementation
import Foundation
public class Promise<T> {
public typealias PromiseSuccessBlock = (result: T) -> Void
public typealias PromiseFailureBlock = (error: NSError?) -> Void
public typealias PromiseAlwaysBlock = () -> Void
private(set) var successBlocks = [PromiseSuccessBlock]()
private(set) var failureBlocks = [PromiseFailureBlock]()
@atomkirk
atomkirk / UIColor+Hex.swift
Last active September 3, 2015 21:23
Swift UIColor Hex
import UIKit
extension UIColor {
convenience init(red: Int, green: Int, blue: Int) {
assert(red >= 0 && red <= 255, "Invalid red component")
assert(green >= 0 && green <= 255, "Invalid green component")
assert(blue >= 0 && blue <= 255, "Invalid blue component")
self.init(red: CGFloat(red) / 255.0, green: CGFloat(green) / 255.0, blue: CGFloat(blue) / 255.0, alpha: 1.0)
}
@atomkirk
atomkirk / NSLayoutManager-coordinates.md
Last active September 11, 2015 02:29
Can't get correct coordinates using TextKit with UITextView?
@atomkirk
atomkirk / logging.swift
Created September 23, 2015 16:06
Debug Loggin In Swift
#if DEBUG
func dLog(message: AnyObject, filename: String = __FILE__, function: String = __FUNCTION__, line: Int = __LINE__) {
NSLog("%@", "[\(filename):\(line)] \(function) - \(message)")
}
func uLog(message: AnyObject, filename: String = __FILE__, function: String = __FUNCTION__, line: Int = __LINE__) {
let message = NSString(format: "%@", "\(function) - \(message)") as String
let alertView = UIAlertView(title: "[\(filename):\(line)]", message: message, delegate:nil, cancelButtonTitle:"OK")
alertView.show()
}
@atomkirk
atomkirk / download_heroku_db.md
Last active December 17, 2015 09:39
Download Heroku DB
  1. Use heroku pgbackups to get url of latest backup:

     heroku pgbackups:url
    
  2. Download the .dump file.

  3. Create a db to restore into:

     psql -c "create database firehose_live_backup"
    

(note: show current dbs with psql then \list)

@atomkirk
atomkirk / dup_pg_db.md
Created May 16, 2013 02:08
Duplicate a postgres DB

To create a copy of a database, first make sure the destination doesn't exist:

psql -c "DROP DATABASE firehose_development;"

Then:

psql -c "CREATE DATABASE firehose_development WITH TEMPLATE firehose_test;"