Skip to content

Instantly share code, notes, and snippets.

View atomkirk's full-sized avatar

Adam Kirk atomkirk

View GitHub Profile
@atomkirk
atomkirk / pipe-quoted.md
Created April 21, 2017 12:27
Pipe list of quoted expressions together

If you're building an Elixir DSL that has this form:

some_macro "title" do
  some "functions"
  that "are"
  called "one"
  after "another"
  but "build"
 a "structure"
@atomkirk
atomkirk / css-spacing-rules.scss
Last active December 8, 2016 19:45
Generates css rules for layout spacing/margin
@function short-prefix($prefix) {
@if $prefix == 'margin' {
@return 'm';
}
@elseif $prefix == 'padding' {
@return 'p';
}
}
@function short-direction($direction) {
@atomkirk
atomkirk / gist:ca05235ff428c51882dea99bfdc973d9
Created December 1, 2016 19:05
deliciously private way to get current route state
let router = Ember.getOwner(this).lookup('router:main')
let queryParams = router.currentState.routerJsState.queryParams;
@atomkirk
atomkirk / app%components%each-saved.js
Last active October 20, 2016 13:40
Ember.js component to replace #each template helper that only iterates over records that are saved.
import Ember from 'ember';
const EachRecordComponent = Ember.Component.extend({
tagName: '',
savedRecords: Ember.computed.filterBy('records', 'isNew', false)
});
@atomkirk
atomkirk / application_record.rb
Created June 29, 2016 18:47
token for temporary values
has_many :tokens, as: :tokenable, dependent: :destroy
@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 / NSLayoutManager-coordinates.md
Last active September 11, 2015 02:29
Can't get correct coordinates using TextKit with UITextView?
@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 / 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]()
//
// Q.swift
// Created by Adam Kirk on 6/6/15.
//
import Foundation
public typealias QBlock = () -> Void
func serialQueueWithName(name: String) -> NSOperationQueue {