Skip to content

Instantly share code, notes, and snippets.

@maddiesch
maddiesch / README.md
Created April 23, 2017 22:52
Systemd Sidekiq Capistrano

Systemd managed Sidekiq

This assumes that sidekiq.service is located in <rails root>/lib/services/sidekiq.service

@maddiesch
maddiesch / clean-url
Created May 17, 2016 16:56
Print valid query options from a URL
#!/usr/bin/env ruby
##
# $ clean-url "http://services.pco.dev/songs?arrangement_name=&author=&bpm_max=&bpm_min=&commit=Apply+Filter&filtered_ministry_path=%2F13%2F14%2F18%2F&key_name=&lyrics=&meter=&music_key=&music_key_end=&music_key_end_major=Major&music_key_major=Major&selection_arrangement_field_15=true&selection_song_option_72=true&song_name=&themes=&utf8=%E2%9C%93"
#
# ******************************************************
# * commit => Apply+Filter *
# * filtered_ministry_path => /13/14/18/ *
# * music_key_end_major => Major *
# * music_key_major => Major *
@maddiesch
maddiesch / truncate-logs
Created January 14, 2016 21:22
Truncate all logs
#!/bin/bash
# brew install coreutils
find $(pwd) -name '*.log' | xargs gtruncate --size 0
@maddiesch
maddiesch / b-search.swift
Last active December 17, 2015 05:43
Playing with CS stuff
//: Playground - noun: a place where people can play
import UIKit
class Node<T : Hashable> : CustomStringConvertible {
weak var parent: Node? {
get { return _parent }
}
var left: Node? {
@maddiesch
maddiesch / Distance.swift
Created September 23, 2015 18:20
Calculate the distance between 2 coordinates
extension Float {
var radians: Float {
get {
return self * Float(M_PI / 180.0)
}
}
}
struct Location {
let radius: Float = 3961.0
@maddiesch
maddiesch / presence.rb
Created April 17, 2015 06:05
RSpec Helpers
# In spec/support/presence.rb
RSpec.shared_examples 'presence' do |attrs|
describe 'presence validations' do
attrs.each do |attr|
it "checks presence of #{attr}" do
target = described_class.name.downcase.to_sym
obj = FactoryGirl.build target, attr.to_sym => nil
expect(obj.valid?).to eq false
expect(obj.errors[attr.to_sym].size).to eq 1
end
@maddiesch
maddiesch / Distance.h
Created March 13, 2015 17:26
Get distance between two points
UIKIT_EXTERN CGFloat SKYDistanceFromPointToPoint(CGPoint, CGPoint);
#import <Foundation/Foundation.h>
@interface NSDate (Additions)
+ (instancetype)dateWithISO8601DateString:(NSString *)date;
+ (instancetype)dateWithISO8601DateTimeString:(NSString *)date;
@end
@interface NSDateFormatter (Additions)
@maddiesch
maddiesch / size.rb
Created February 5, 2015 22:50
We have massive .xcassets catalogs. This helps verify the @2x & @3x assets are the right sizes.
#
# Used to valide image sizes in an Xcode asset cataloge.
#
# If a @1x image is 100x100 this will verify the @2x is 200x200 (+/- 4) and the @3x is 300x300 (+/- 4)
#
# Usage:
# ruby size.rb /full/path/to/assets/Images.xcassets
#
# Output:
# image@3x.png
int32_t hex = 0x2578CB;
[[UIColor alloc] initWithRed:(((hex >> 16) & 0xFF) / 255.0) green:(((hex >> 8) & 0xFF) / 255.0) blue:((hex & 0xFF) / 255.0) alpha:1.0];