Skip to content

Instantly share code, notes, and snippets.

👨‍💻
Coding!

Andrew Crookston acrookston

👨‍💻
Coding!
Block or report user

Report or block acrookston

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@acrookston
acrookston / parse_colors.rb
Last active Dec 26, 2015
Cross-posting from https://forrst.com/posts/Collecting_colours_from_an_image_Ruby-Lgo Collecting colours from an image with Ruby
View parse_colors.rb
require 'rmagick'
number_of_colors = 100
file_path = "/path/to/file.jpg"
begin
temp_file = Magick::Image.read(file_path).first.quantize(number_of_colors)
pixels = {}
pixel_count = 0
temp_file.each_pixel do |p,c,r|
pixel_count += 1
pix = p.to_color(Magick::AllCompliance, false, 8)
@acrookston
acrookston / etc_init_sidekiq.conf
Last active Dec 28, 2015
sidekiq rvm ubuntu upstart config
View etc_init_sidekiq.conf
# /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
View pngout.rb
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 Jan 17, 2016
rendered gitconfig from acrookston/dotfiles
View .gitconfig
[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 Mar 20, 2016
Keychain struct for Locksmith using accessible option.
View SecureKeyValue.swift
//
// SecureKeyValue.swift
//
// Created by Andrew Crookston <andrew@caoos.com> on 1/5/16.
// Copyright © 2016. License: MIT.
//
import Foundation
import Locksmith
View enumerable.rb
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(:+))
View UICollectionViewExtension.swift
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 {
View NavBarButtons.swift
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 }
View NavBarButtonStub.swift
class NavBarItem {
typealias Callback = (() -> ())
var title : String
var selected: Bool
var callback: Callback
init(title: String, selected: Bool, callback: @escaping Callback) {
View linked_list.swift
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) {
You can’t perform that action at this time.