Skip to content

Instantly share code, notes, and snippets.

Avatar

Brad Johnson cdale77

View GitHub Profile
@cdale77
cdale77 / highlight.sh
Created Jul 16, 2016
Paste with syntax highlighting
View highlight.sh
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
Rubocop configuration file
View rubocop.yml
AllCops:
Exclude:
- 'db/**/*'
TargetRubyVersion: 2.3
Rails:
Enabled: true
########################## Lint ################################
@cdale77
cdale77 / rspec_rails_cheetsheet.rb
Created May 12, 2016 — forked from them0nk/rspec_rails_cheetsheet.rb
Rspec Rails cheatsheet (include capybara matchers)
View rspec_rails_cheetsheet.rb
#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)
View pronto_on_circle.yml
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 Jul 25, 2014
Recursively copy and rename files with Ruby
View gist:d8502ef11373862f8eaa
#!/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 Apr 19, 2014
OpenRefine functions
View refine.txt
## 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