Skip to content

Instantly share code, notes, and snippets.

View johncarney's full-sized avatar

John Carney johncarney

  • Victor, Idaho
View GitHub Profile
@johncarney
johncarney / example.rb
Created August 7, 2012 11:26
Split a Ruby Enumerable into chunks divided by an arbitary number of patterns
%w{ a b c d e f }.split("c", "e")
# => [["a", "b"], ["c", "d"], ["e", "f"]]
@johncarney
johncarney / remove-duplicates.sh
Created November 23, 2012 02:19
Remove duplicates from "Open With..." menu
/System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister -kill -r -domain local -domain system -domain user
@johncarney
johncarney / resize-brush-in-photoshop.md
Last active August 29, 2015 14:07
How to adjust brush size and hardness in Photoshop on Mac OS X

Resizing Brushes in Photoshop

To adjust brush size

Hold down ⌃⌥ and drag the mouse left (smaller) or right (larger).

Or use the [ key (smaller) and ] key (larger).

To adjust brush hardness

@johncarney
johncarney / newsyslog-for-your-project.conf
Last active March 1, 2024 22:14
Example newsyslog configuration for rotating Rails log files on Mac OS X.
# logfilename [owner:group] mode count size when flags [/pid_file] [sig_num]
/Users/your-username/path-your-rails-project/log/*.log your-username:staff 644 4 * $D0 GJ
# NOTES
#
# Place file in /etc/newsyslog.d
# '$D0' under 'when' tells newsyslog to rotate logs daily at midnight.
# Alternatively you could use '24' for 'when', which would specify "every 24 hours"
# '*' under 'size' specifies that logs should be rotated regardless of their size.
# 'G' under 'flags' tells newsyslog that the 'logfilename' is a pattern and it should rotate all log files matching the pattern.
@johncarney
johncarney / keybase.md
Created January 9, 2015 06:12
Keybase

Keybase proof

I hereby claim:

  • I am johncarney on github.
  • I am johncarney (https://keybase.io/johncarney) on keybase.
  • I have a public key whose fingerprint is 1D0F 663E BE56 A61B 6A17 C152 2ECF 52DC 5C72 1574

To claim this, I am signing this object:

@johncarney
johncarney / flex_struct.rb
Last active August 29, 2015 14:24
FlexStruct: Wrapper around Ruby's Struct with a more flexible initializer.
module FlexStruct
def initialize(*args, **options)
super(*args, *options.values_at(*members[args.length..-1]))
end
def self.new(*args, &block)
Struct.new(*args, &block).include self
end
end
@johncarney
johncarney / _readme.md
Last active February 19, 2016 06:58
Calculating with functions
@johncarney
johncarney / reek-to-markdown.rb
Created May 19, 2016 01:35
Convert output of reek to GitHub-flavoured Markdown
#!/usr/bin/env ruby
# Converts the output from reek to GitHub-flavoured Markdown.
#
# Usage:
# Basically pipe the output from reek through this script.
#
# reek --sort-by smelliness app lib | ruby reek-to-markdown.rb
def scan_line(line, pattern)
@johncarney
johncarney / prefix.rb
Created November 13, 2016 10:13
Find the longest common prefix of a bunch of arrays, or a bunch of strings
def common_array_prefix(*arrays)
arrays.reduce do |a, b|
index = a.zip(b).index { |x, y| x != y }
a[0...index]
end
end
def common_string_prefix(*strings)
common_array_prefix(*strings.map(&:chars)).join("")
end
@johncarney
johncarney / rails-locales-conflicts.rb
Last active January 3, 2017 02:58
Lists conflicting translations from your Rails locale files. Note that it will only detect conflicts between different locale files. Conflicts within a single locale file will not be detected.
#!/usr/bin/env ruby
# Usage: ruby rails-locales-conflicts.rb [<rails root>]
require "pathname"
require "yaml"
class Translations
def initialize
@translations = Hash.new do |h, k|