Skip to content

Instantly share code, notes, and snippets.

View delameko's full-sized avatar

Matt Slater delameko

View GitHub Profile
@delameko
delameko / .gemrc
Last active August 29, 2015 14:18 — forked from jch/.gemrc
A .gemrc example
# http://guides.rubygems.org/command-reference/#gem-environment
---
gem: --no-ri --no-rdoc
benchmark: false
verbose: true
update_sources: true
backtrace: true
bulk_threshold: 1000
@delameko
delameko / 0_reuse_code.js
Last active August 29, 2015 14:26
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@delameko
delameko / .gemrc
Created July 31, 2015 11:42
Default .gemrc
# http://guides.rubygems.org/command-reference/#gem-environment
---
gem: --no-ri --no-rdoc
benchmark: false
verbose: true
update_sources: true
backtrace: true
bulk_threshold: 1000
@delameko
delameko / is_dom_ready.js
Created August 22, 2015 17:26
Check that the page has finished loading
// The basic check
if(document.readyState === 'complete') {
// good to go!
}
// Polling for the sake of my intern tests
var interval = setInterval(function() {
if(document.readyState === 'complete') {
clearInterval(interval);
done();
@delameko
delameko / SmartTruncate.rb
Created August 18, 2009 14:45
Smart Truncate
module ApplicationHelper
def smart_truncate(s, opts = {})
opts = {:words => 12}.merge(opts)
if opts[:sentences]
return s.split(/\./)[0, opts[:sentences]].map{|s| s.strip}.join('. ') + '.'
end
a = s.split(/\s/) # or /[ ]+/ to only split on spaces
n = opts[:words]
a[0...n].join(' ') + (a.size > n ? '...' : '')
@delameko
delameko / DiffmergeAsGitMerge.sh
Created September 8, 2015 15:25
Using DiffMerge as difftool in git
git config --global diff.tool diffmerge
git config --global difftool.diffmerge.cmd 'diffmerge "$LOCAL" "$REMOTE"'
git config --global merge.tool diffmerge
git config --global mergetool.diffmerge.cmd 'diffmerge --merge --result="$MERGED" "$LOCAL" "$(if test -f "$BASE"; then echo "$BASE"; else echo "$LOCAL"; fi)" "$REMOTE"'
git config --global mergetool.diffmerge.trustExitCode true
@delameko
delameko / RailsHTTPStatusCodes.md
Last active September 19, 2015 11:02
Rails HTTP status codes/symbol names

###1xx Informational

code message symbol
100 Continue :continue
101 Switching Protocols :switching_protocols
102 Processing :processing

###2xx Success

@delameko
delameko / regular_expression_patterns.rb
Last active September 27, 2015 15:28
Useful regular expressions for Ruby
# Useful regular expressions
# http://net.tutsplus.com/tutorials/other/8-regular-expressions-you-should-know/
# username
/^[a-z0-9_-]{3,16}$/
# password
/^[a-z0-9_-]{6,18}$/
# Hex value
@delameko
delameko / append_bundle_exec.sh
Last active September 28, 2015 12:28 — forked from tapajos/gist:1433859
Script to automatically append 'bundle exec' to the start of a command if there is a Gemfile in the folder.
function rake {
if [ -e Gemfile ]; then
bundle exec rake $@
else
`which rake` $@
fi
}
function rspec {
if [ -e Gemfile ]; then
@delameko
delameko / pow_port.rb
Created January 16, 2012 15:31 — forked from dhrrgn/pow_port.rb
Quickly and easily change the port that Pow is running on. This allows you too run Apache and Pow side-by-side (on different ports of course).
#!/usr/bin/env ruby
# Pow Port
#
# Quickly and easily change the port that Pow is running on. This allows
# you too run Apache and Pow side-by-side (on different ports of course).
#
# WARNING: This will OVERWRITE your ~/.powconfig file. If you have custom
# configurations in there, please back it up first.
#