Skip to content

Instantly share code, notes, and snippets.

View cdale77's full-sized avatar

Brad Johnson cdale77

View GitHub Profile
@cdale77
cdale77 / highlight.sh
Created July 16, 2016 20:23
Paste with syntax highlighting
highlight -O rtf -t 2 -K 40 -k 'Source Code Pro' --style edit-vim app/controllers/pokemons_controller.rb | pbcopy
@cdale77
cdale77 / rubocop.yml
Created May 25, 2016 17:29
Rubocop configuration file
AllCops:
Exclude:
- 'db/**/*'
TargetRubyVersion: 2.3
Rails:
Enabled: true
########################## Lint ################################
@cdale77
cdale77 / rspec_rails_cheetsheet.rb
Created May 12, 2016 18:50 — forked from them0nk/rspec_rails_cheetsheet.rb
Rspec Rails cheatsheet (include capybara matchers)
#Model
@user.should have(1).error_on(:username) # Checks whether there is an error in username
@user.errors[:username].should include("can't be blank") # check for the error message
#Rendering
response.should render_template(:index)
#Redirecting
response.should redirect_to(movies_path)
test:
pre:
- "[[ ! -s \"$(git rev-parse --git-dir)/shallow\" ]] || git fetch --unshallow"
post:
- bundle exec pronto run -f github -c=$(git log --pretty=format:%H | tail -1)
@cdale77
cdale77 / gist:d8502ef11373862f8eaa
Created July 25, 2014 22:19
Recursively copy and rename files with Ruby
#!/usr/bin/env ruby
require 'fileutils'
files = Dir["*/*.PDF"].collect{|f| File.expand_path(f)}
files.each_with_index do |file, index|
puts "copying file #{index}"
FileUtils.cp file, "pdf/#{index}.pdf"
end
@cdale77
cdale77 / refine.txt
Created April 19, 2014 06:10
OpenRefine functions
## Remove common characters from phone numbers.
value.replace("-","").replace(".","").replace("-","").replace("(","").replace(")","").replace(" ","")
## Takes phone numbers formatted as 5555555555 and formats them as 555-555-5555
value.slice(0,3) + "-" + value.slice(3,6) + "-" + value.slice(6,10)
## add zeros to the front of zip codes. Useful for when Excel removes them.
"000000"[0,10-value.length()] + value