Skip to content

Instantly share code, notes, and snippets.

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

Andrew Crookston acrookston

👨‍💻
Coding!
View GitHub Profile
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 / fizzbuzz.rb
Created September 23, 2014 01:07
Cross-posting my FizzBuzz challenge from Forrst: http://zurb.com/forrst/posts/FizzBuzz-R33
(1..100).each{|i| puts (i%3==0?'Fizz': '')+(i%5==0?'Buzz': '')+(i%3==0||i%5==0?'': i.to_s)}
@acrookston
acrookston / HeaderCollectionViewController.swift
Last active February 26, 2018 01:15
UICollectionView example in Swift
class HeaderCollectionViewController: UIViewController, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout, UICollectionViewDelegate {
var collectionView : UICollectionView?
override func viewDidLoad() {
super.viewDidLoad()
var layout = CSStickyHeaderFlowLayout()
layout.parallaxHeaderReferenceSize = CGRectMake(... size of the header...)
layout.minimumInteritemSpacing = 0
@acrookston
acrookston / ImageZoom.swift
Created January 14, 2015 19:12
Swift image zoom
// The image is originally animated on to the view controller then added to the scroll view.
// So, there might be some animation residue in here.
// Class needs: <UIScrollViewDelegate>
func viewDidLoad() {
let width = UIScreen.mainScreen().bounds.size.width
let aspect: CGFloat = width / shotWidth
var frame = CGRectMake(0, 0, shotWidth * aspect, shotHeight * aspect)
self.scrollView = UIScrollView(frame: frame)
@acrookston
acrookston / proc_mem_pid
Last active April 7, 2022 20:00
Munin plugin for monitoring memory usage based on process id's
#!/bin/sh
#
# (c) 2015, Andrew Crookston <andrew@caoos.com>
# Licence: GPLv2
#
# Configure it by using the pidfiles env. Format: name:pidfile name:pidfile. e.g.:
#
# [proc_mem_pid]
# env.pidfiles munin-node:/var/run/munin/munin-node.pid
#
@acrookston
acrookston / proc_cpu_pid
Last active May 24, 2023 21:59
Munin plugin to track CPU usage from specific processes based on process id's
#!/bin/sh
#
# Extended 2015 by Andrew Crookston <andrew@caoos.com> to use pidfiles instead of process names
# Original (c) 2010, Andrew Johnstone andrew @ajohnstone.com
# Based on the 'proc_mem' plugin, written by Rodrigo Sieiro rsieiro @gmail.com
#
# Configure it by using the pidfiles env. Format: name:pidfile name:pidfile. e.g.:
#
# [proc_cpu_pid]
# env.pidfiles munin-node:/var/run/munin/munin-node.pid
@acrookston
acrookston / example.rb
Last active August 29, 2015 14:17
Rails update_attributes without updating the updated_at field
class Example < ActiveRecord::Base
include WithoutTimestamps
def update_something
update_without_timestamps something: "is changed"
end
def alternatively
self.something = "is changed"
update_without_timestamps
@acrookston
acrookston / StretchCollectionViewFlowLayout.swift
Created May 8, 2015 21:31
Strechy UICollectionView section header
//
// StretchCollectionViewFlowLayout.swift
//
// Created by Andrew C on 5/8/15.
//
import UIKit
class StretchCollectionViewFlowLayout: UICollectionViewFlowLayout {
@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