Skip to content

Instantly share code, notes, and snippets.

Useful Vim mappings

...you didn't know you wanted

Convert Ruby 1.8 to 1.9 hash syntax

nnoremap <Leader>: :%s/:\([^ ]*\)\(\s*\)=>/\1:/gc<CR>
@calebhearth
calebhearth / gist:4625280
Created January 24, 2013 17:15
Switch back and forth between directories and git branches, and even merge the last branch you were on, with hyphen!
~/
↪ cd code/project
project[master]/
↪ cd -
~/
↪ cd code/project
project[master]/
@calebhearth
calebhearth / gem_with_dummy.sh
Last active December 12, 2015 08:09
./gem_with_dummy.sh tiberius
gemname=$1
bundle gem $gemname
cd $gemname
git commit -am"bundle gem $gemname"
git checkout --orphan dummy
git rm -rf .
cd ..
rails plugin new $gemname \
--skip-bundle \
--skip-keeps \
#!/usr/bin/env bash
branch_pattern="^## (.*)$"
git_status=`git status -sb`
if [[ $git_status =~ $branch_pattern ]]
then
echo ${BASH_REMATCH[1]}
fi
@calebhearth
calebhearth / patch.diff
Last active December 16, 2015 04:19
Rails issue #4936
diff --git a/activerecord/lib/active_record/core.rb b/activerecord/lib/active_record/core.rb
index 7a84081..dd8f589 100644
--- a/activerecord/lib/active_record/core.rb
+++ b/activerecord/lib/active_record/core.rb
@@ -307,15 +307,16 @@ module ActiveRecord
id.hash
end
- # Freeze the attributes hash such that associations are still accessible, even on destroyed records.
+ # Freeze the attributes hash such that associations are still accessible,
@calebhearth
calebhearth / checking-rebases
Created April 13, 2013 00:33
Proof that git-rebase destroys merge commits
cd
mkdir checking-rebases
cd checking-rebases
git init
echo "1" >> file-1
git add file-1
git commit -m 1
git checkout -b 2
echo "2" >> file-2
git add file-2
unless File.exists?('Gemfile')
File.write('Gemfile', <<-GEMFILE)
source 'https://rubygems.org'
gem 'rails', path: '/Users/caleb/code/rails'
gem 'sqlite3'
GEMFILE
system 'bundle'
end
void calculate() {
unsigned int neighbors;
for (int m = 0; m < H; m++) {
for (int n = 0; n < W; n++) {
neighbors = 0;
//Begin counting number of neighbors:
// 123
// 4x6 Array locations for ease of reading
// 789

Steve asked me to give a little feedback on the contributing guide based on a conversation we had on twitter wherein I mentioned that the process of shepherding a pull request to completion was opaque to me.

I like to think that I have a fair idea of how to contribute to open source generally, but haven't had much luck with Rails specifically. There's actually a running joke at work that while I might put work into a new feature or to fixing a bug, it'll never get merged so it doesn't matter.

...gNMMM@@MMMNa+..
..M@M#"=!........?7TWMMN&,
..MMY=...`.....`...```....?YMMa.
.JM#^..``.```````````````....`.JW@N.
.M#^.``.`.```````````````.`..````.,WMh.
.MM5.J.J..```.````````..`.JJ.,,`...``.JMN.
.MM.JY^` .MMa .```````.`.M"= .dMN,`.`.`.MM,
[email protected]$ @@MMN.``````.`dF J@@MMp````..MM,
M@^JF ?WH"Jb .`````JF "H"^M,..```.@N
JMF dF JN `````.@F gF `.`.`J@F