Skip to content

Instantly share code, notes, and snippets.

@joshmcarthur
joshmcarthur / .vimrc
Created February 3, 2015 22:21
Relative line number toggles in Vim
" --- snip ---
" Relative Numbering
" =======
:au FocusLost * :set number
:au FocusGained * :set relativenumber
autocmd InsertEnter * :set number
autocmd InsertLeave * :set relativenumber
" --- snip ---
@joshmcarthur
joshmcarthur / keybase.md
Created October 14, 2014 02:31
Keybase Verification File

Keybase proof

I hereby claim:

  • I am joshmcarthur on github.
  • I am sudojosh (https://keybase.io/sudojosh) on keybase.
  • I have a public key whose fingerprint is F836 E081 B5FC 98B7 4731 9535 8185 E264 85E5 3C23

To claim this, I am signing this object:

#!/bin/sh
# Some things taken from here
# https://github.com/mathiasbynens/dotfiles/blob/master/.osx
# Set the colours you can use
black='\033[0;30m'
white='\033[0;37m'
red='\033[0;31m'
green='\033[0;32m'
@joshmcarthur
joshmcarthur / spec_helper.rb
Last active August 29, 2015 14:05
Disable logging from Authority while running tests (e.g. `User #123 is not authorized...`)
# Turn off authority logging while running tests
Authority.configure do |config|
config.logger = Logger.new('/dev/null')
end
@joshmcarthur
joshmcarthur / model.rb
Last active August 29, 2015 14:05
Safe assignment of unique token with collision checking
def set_access_token
begin
self.access_token = Devise.friendly_token[0..12]
end while ClientForm.exists?(access_token: self.access_token)
end
@joshmcarthur
joshmcarthur / -
Created August 1, 2014 06:33
Allow using capital letters in API module
# config/initializers/inflections.rb
ActiveSupport::Inflector.inflections(:en) do |inflect|
inflect.acronym 'API'
end
# app/controllers/api/widgets_controller.rb
module API
class WidgetsController < BaseController
end
end
@joshmcarthur
joshmcarthur / csv_renderer.rb
Created July 21, 2014 00:43
Support rendering CSV content directly as an attachment
# Save this in config/initializers/csv_renderer.rb
ActionController::Renderers.add :csv do |obj, options|
filename = options[:filename] || 'data.csv'
str = obj.respond_to?(:to_csv) ? obj.to_csv : obj.to_s
send_data str,
type: Mime::CSV,
disposition: "attachment",
filename: filename
end
@joshmcarthur
joshmcarthur / README.md
Last active August 29, 2015 14:03
A6 Printing Template

About

The file attached to this Gist in XCF format is a template ready for professional printing with correct bleed and safety margins applied for editing in GIMP. Feel free to download and use it for your own projects. I've created this file because while I found a bunch of instructions on how to set up the file, I couldn't find a good starter. Here it is! I've followed the instructions on The Online Printer's guide to preparing GIMP files, but I also welcome any additional tips.

Usage

  1. Download the file
  2. Make changes as required:
  3. Treat the first level of guides as the edge of your image. This is the bleed line, and you can expect that this would normally be cropped.
  4. Treat the second level of guides as the safety margin. You should not have any important content or imagery crossing this margin.
pp (YourClass.methods - Object.methods).sort
@joshmcarthur
joshmcarthur / pbcopy.md
Created May 4, 2014 21:14
Copy terminal text to clipboard

Variant 1:

pbcopy < file.txt

Variant 2:

command | pbcopy