Skip to content

Instantly share code, notes, and snippets.

View acrookston's full-sized avatar
👨‍💻
Coding!

Andrew Crookston acrookston

👨‍💻
Coding!
View GitHub Profile
@acrookston
acrookston / etc_init_sidekiq.conf
Last active December 28, 2015 10:59
sidekiq rvm ubuntu upstart config
# /etc/init/sidekiq.conf - Sidekiq config
# This example config should work with Ubuntu 12.04+. It
# allows you to manage multiple Sidekiq instances with
# Upstart, Ubuntu's native service management tool.
#
# See workers.conf for how to manage all Sidekiq instances at once.
#
# Save this config as /etc/init/sidekiq.conf then mange sidekiq with:
# sudo start sidekiq index=0
require 'formula'
class Pngout < Formula
url 'http://static.jonof.id.au/dl/kenutils/pngout-20110722-darwin.tar.gz'
homepage 'http://www.jonof.id.au/kenutils'
md5 'ce70a9d70e08b1920e5ac88d130d0eb9'
version '20110722'
def install
prefix.install Dir['*']
@acrookston
acrookston / .gitconfig
Created January 17, 2016 04:22
rendered gitconfig from acrookston/dotfiles
[core]
excludesfile = /Users/!!!INSERT YOUR COMPUTER USERNAME!!!/.gitignore
[push]
default = current
[color]
ui = true
[user]
name = !!!INSERT YOUR NAME!!!
email = !!!INSERT YOUR EMAIL!!!
[github]
@acrookston
acrookston / SecureKeyValue.swift
Last active March 20, 2016 18:46
Keychain struct for Locksmith using accessible option.
//
// SecureKeyValue.swift
//
// Created by Andrew Crookston <andrew@caoos.com> on 1/5/16.
// Copyright © 2016. License: MIT.
//
import Foundation
import Locksmith
module Enumerable
def normalize
magnitude = Math.sqrt(reduce(:+))
return self if magnitude.nan?
map { |x| x.to_f / magnitude }
end
def similarity(arr)
return 0.0 if arr.count != count
similarity = Math.sqrt(zip(arr).map { |d| d.first * d.second }.reduce(:+))
extension UICollectionView {
func indexPathsForCloseItems(offset: Int) -> [IndexPath] {
var indexes = indexPathsForVisibleItems.sorted(by: { $0.row < $1.row })
for x in indexes {
print("had: \(x)")
}
if let index = indexes.last {
protocol NavButtonProtocol: RawRepresentable {
var title : String { get }
}
//extension NavButtonProtocol where Self : RawRepresentable, Self.RawValue == String {
// static var count: Int {
// var max: Int = 0
// while let _ = self.init(rawValue: max) { max += 1 }
class NavBarItem {
typealias Callback = (() -> ())
var title : String
var selected: Bool
var callback: Callback
init(title: String, selected: Bool, callback: @escaping Callback) {
class LinkedListNode<T> {
var next : LinkedListNode<T>?
var value: T
var count : Int {
return next == nil ? 1 : next!.count + 1
}
init(_ value: T, _ next: LinkedListNode<T>?=nil) {
@acrookston
acrookston / EnumExtensions.swift
Created April 26, 2017 22:24
Swift extension to make Enums enumerable
protocol EnumCollection : Hashable {}
extension EnumCollection {
static func enumerated() -> AnySequence<Self> {
typealias S = Self
return AnySequence { () -> AnyIterator<S> in
var raw = 0
return AnyIterator {
let current = withUnsafePointer(to: &raw) {
$0.withMemoryRebound(to: S.self, capacity: 1) { $0.pointee }