Releasing geordi
After having written useful scripts into makandra notes for a long time, we’ve now tied them into a powerful new gem: geordi.
It gives you the power to
- get a dump from your production database with
dump-for production
- install your local gems to the production machine with
install-gems-remotely
- execute rake tasks to several environments at the same time with
power-rake db:migrate
- and much more
Updating a gem created with Bundler
Since May 2011 we are cutting new gems using Bundler, which is less painful than cutting gems using Jeweler. You know a gem was cut using Bundler if you see the word Bundler
in a gem project's Rakefile
.
This is how to update a gem that was cut using Bundler:
- Say
git pull
or check out a repository from Github likegit clone git@github.com:makandra/geordi.git
- Update the gem version in `lib/project...
Script to open an SSH shell to a Capistrano deployment target
We regularly need to connect to the server in order to e.g. access the production console. Guessing the Capistrano deploy user and then again guessing the right directory on the server is awkward, so we wrote a script that parses config/deploy and gives you the handy command shell-for
.
Run it from any project directory like this, passing a Capistrano multistage deployment target:
shell-for staging
Now it also supports commands to be remotely executed before loading the bash. Use --no-bash
to only execute the command and load no ba...
Bash script to run specs and features
Run rspec-and-cucumber
from any project directory to run both RSpec and Cucumber. If available, rspec_spinner or cucumber_spinner are used.
Note that features are not run when specs fail.\
If you prefer to run them in parallel or run features regardless of the spec results, please adjust it for yourself accordingly.
This script is part of our geordi gem on github.
Git Cheatsheet
Make sure you understand differences between git's areas (such as stash, workspace, upstream, etc.) and what commands affect which areas.
javan/whenever - GitHub
Whenever is a Ruby gem that provides a clear syntax for writing and deploying cron jobs.
Git: Advisory for cherry-picks to production branches
We often have a separate production branch that lags a bit behind the more cutting edge main branch. Sometimes you want to move some, but not all commits from main to production. This can be done with a git cherry-pick
.
However, this may lead to considerable pain later, since git does not understand the commits are actually "the same". Hazards are unnecessary and hard to resolve conflicts as well as incorrect auto-merges.
In order to avoid this, always merge the production branch back to the main after the cherry-pick. Even t...
Speed up Capistrano deployments using a remote cached copy of repository
You can seriously speed up deployments with Capistrano when using a local git repository on the server you are deploying to.
Simply add
set :deploy_via, :remote_cache
set :copy_exclude, [ '.git' ]
to your config/deploy.rb
and Capistrano will create a clone in shared/cached-copy
. This will be updated using git pull
when deploying which transfers less bytes and is usually much faster. If deploy_via
is set to use default settings (being "export
"), Capistrano will do a full clone of the repository from your git host otherwi...
Ignore an error class with Airbrake
Airbrake (formerly Hoptoad) already ignores certain errors like InvalidAuthenticityToken
by default (see Airbrake::Configuration::IGNORE_DEFAULT
).\
To ignore additional classes of errors, put this into config/initializer/airbrake.rb
:
Airbrake.configure do |config|
config.ignore << 'ActiveRecord::IgnoreThisError'
end
You probably also want to ignore ActionController::MethodNotAllowed
and ActionController::UnknownHttpMethod
exceptions.
See the github page for more options on h...
List your current Git remotes
To display a list of your current Git remotes and their endpoints, you can say
git remote -v
The output looks like this:
brady8 https://github.com/brady8/aegis.git (fetch)
brady8 https://github.com/brady8/aegis.git (push)
origin git@github.com:makandra/aegis.git (fetch)
origin git@github.com:makandra/aegis.git (push)
Convert RDoc markup to HTML
If you want to convert a README.rdoc
file to HTML, say this from a shell:
rdoc README.rdoc
You will find the generated HTML in doc/index.html
.
If you do this while working on one of our gems, please .gitignore
everything in doc
and don't commit the generated HTML.
Dropbox + git = Designer <3
One of the thornier problems in our workflow is knowing when assets are delivered from the designer and keeping them in sync with our application as they change. We used to use e-mail, Skype or sticky notes. The trouble is that the designer's file naming and directory structure were never quite the same as the application's /public/images directory, so direct comparisons were impossible and we ended with a lot bookkeeping to make sure that we didn't lose any changes. Our solution is to clone the project's git repository into a folder inside ...
Generate Puppet or Chef recipes from a Ubuntu system state
blueprint is DevStructure’s workhorse tool that looks inside popular package managers, finds changes you made to configuration files, and archives software you built from source to generate Puppet, Chef, or shell code. Everything blueprint sees is stored in Git to be diffed and pushed. It runs on Ubuntu Linux 10.04 and newer.
Upgrading Cucumber and Capybara to the latest versions available for Rails 2
Specify these gem versions in your Gemfile:
gem 'cucumber', '~> 1.3.0'
gem 'cucumber-rails', '= 0.3.2' # max version for Rails 2
gem 'capybara', '< 2' # capybara 2+ requires Rails 3
gem 'mime-types', '< 2' # dependeny of capybara
gem 'nokogiri', '< 1.6' # dependency of capybara
gem 'rubyzip', '< 1' # dependency of selenium-webdriver, rubyzip 1+ requires Ruby 1.9
gem 'cucumber_factory'
gem 'database_cleaner', '< 1'
gem 'cucumber_spinner', '~> 0.2.5'
gem 'launchy', '~> 2.1.2'
With these versions set, `...
Prohibit Git from merging .po-files
Merging .po-files with Git is painful.
There have been attempts of making Git more clever when trying to merge .po-files. I believe however that this is not enough as it can still produce invalid .pos (usually due to double definitions), which can seriously confuse gettext afterwards.
Lacking any more secure solution, I think you should avoid editing po files in different branches at the same time. In order to not accidentally produce invalid merges I additionally ...
Customize your Bash prompt
The shell variable PS1
holds your bash prompt. You might want to change it to serve your needs best. Here is how to:
General
- non-printing escape sequences in your prompt have to be inclosed in
\[\e[
and\]
so your shell can correctly count its prompt's length - we recommend to highlight your prompt on production machines
- you can also [show different root prompts for each user](https://makandracards.com/makandra/9569-get-the-username-w...
plus2/whereuat - GitHub
Adds a slide out panel to your Rails application that directs clients to test stories that have been marked as 'delivered' in Pivotal Tracker.
Dump your database with dumple
This tool is used on our application servers (and called when deploying) but it also works locally.
Just call dumple development
from your project directory to dump your database.
This script is part of our geordi gem on github.
remove_index fails silently for non-existing indexes in Rails 2 migrations
When you try to remove a non-existing index using remove_index
, the migration will incorrectly pass without an error. The schema will not be changed, but the migration will be considered migrated.
Since this might be fixed in the future, you cannot mend your database by adding another migration on top of the faulty one. You should manually alter the database schema to the previous migration on all machines that migrated the faulty migration (inform your fellow developers), then delete the faulty migration from the repository.
OscarGodson/jKey - GitHub
jQuery plugin to register callback functions to keyboard shortkuts. Keyboard events in vanilla Javascripts are super-painful to work with, so hopefully this library can help.
Shell script to clean up a project directory
Call geordi clean
from a project root to remove unused and unnecessary files inside it.
This script is part of our geordi gem on github. In Geordi > 1.2 you can call geordi clean
.
How to: Use git bisect to find bugs and regressions
Git allows you to do a binary search across commits to hunt down the commit that introduced a bug.
Given you are currently on your branch's HEAD that is not working as expected, an example workflow could be:
git bisect start # Start bisecting
git bisect bad # Tag the revision you are currently on (HEAD) as bad. You could also pass a commit's SHA1 like below:
git bisect good abcdef12345678 # Give the SHA1 of any commit that was working as it should
# shorthand:
git bisect start <bad ref> <good ref>
Git will fetch a comm...
Git: See all unpushed commits or commits that are not in another branch
If you need to find out which of your local commits are not on the remote server do this:
git cherry -v
The -v
option prints out the commit messages. Without it you will see only the SHA1 codes.
You may also compare against another (upstream) branch like that:
git cherry -v origin/somebranch
This tool is especially useful when you have a ton of commits after a merge and want to know the commit differences between branches.
Git: Define a custom merge driver
The ‘merge.*.driver` variable’s value is used to construct a command to run to merge ancestor’s version, current version and the other branches’ version. The merge driver is expected to leave the result of the merge in the file named with %A by overwriting it, and exit with zero status if it managed to merge them cleanly, or non-zero if there were conflicts.