Make Capistrano use SSH Key Forwarding
When deploying code with Capistrano (depending on your configuration) at some point Capistrano tries to check out code from your repository. In order to do so, Capistrano connects to your repository server from the application server you're deploying to with SSH. For this connection you can use two SSH keys:
- the user's
~/.ssh/id_rsa
[default] - the very same key you used for connecting to the application server - forwarded automatically to the git repository.
If you prefer the second way, add this to deploy.rb:
ssh_options[:forwar...
Git: Retrieve a file from a different branch or commit
To access files from another branch or past commit without doing a complete checkout, you can either use
git show branch:file
git show commit:file
to display, or check out the file into your working directory with
git checkout branch -- file
git checkout commit -- file
Look up a gem's version history
Sometimes it might be helpful to have a version history for a gem, e.g. when you want to see if there is a newer Rails 2 version of your currently used gem.
At first you should search your gem at RubyGems. Example: will_paginate version history.
The "Tags" tab at GitHub might be helpful as well.
How to fix a corrupt git index
If your git index for some reason becomes invalid, no need to worry.
Your index is corrupt when you see this error running usual git commands like git pull
, git status
, etc.:
error: bad index file sha1 signature
fatal: index file corrupt
Though it sounds bad, your changes are still there. Fix it by first removing the index file, then resetting the branch:
rm .git/index
git reset
You should be all good now.
To be safe, make a backup of .git/index
before you delete it.
nruth/show_me_the_cookies - GitHub
Some helpers for poking around at your Capybara driven browser's cookies in integration tests.
Supports Capybara's bundled drivers (rack-test, Selenium Webdriver), and adapters for other drivers may be added.
paul/progress_bar - GitHub
ProgressBar is a simple Ruby library for displaying progress of long-running tasks on the console. It is intended to be as simple to use as possible.
Git: Moving a commit between repositories
If you want to move a complete commit from one repository to another (and you don't want to add it as a remote), you can use these steps:
Create a patch
In the source repository, create a patch based on the commit by running
git format-patch SHA1_OF_COMMIT~..SHA1_OF_COMMIT # Note the ~
git format-patch HEAD~ # Shortcut for the latest commit
This will create a .patch
file that describes this commit.
Apply the patch
In the target repository, restore the commit from the patch file with
gi...
Git: Diff staged changes
Saying git diff
only shows unstaged changes relative to the index (or HEAD
if the index is empty, alternatively any hash or branch you supplied) but leaves out files you already staged for the next commit.
To diff your added changes with HEAD
, say:
git diff --cached
Effectively, this gives you the changes you will commit when you run git commit
without the -a
switch.
Using Solr with Sunspot
This describes all the steps you'll need to get Solr up and running for your project using the Sunspot gem.
Prepare Sunspot on your development machine
What you want in your Gemfile:
gem 'sunspot_rails'
gem 'sunspot_solr'
gem 'progress_bar' # for sunspot:solr:reindex
Now define what should be indexed within Solr from your ActiveRecord models, e.g.,
class Article << ActiveRecord::Base
searchable do
text :title
...
gammons/fake_arel - GitHub
Gem to get Rails 3's new ActiveRecord query interface (where
, order
) and the new scope syntax (chaining scope definitions) in Rails 2.
You also get #to_sql
for scopes.
colszowka/simplecov - GitHub
Code coverage for Ruby 1.9 with a powerful configuration library and automatic merging of coverage across test suites.
Note that rcov won't ever have support for Ruby 1.9, you're supposed to use rcov for 1.8 and simplecov for 1.9.
Git: What to do when "git log" does not show commits that touch a file
Let's say you have commits that change a file (and looking at the commit details show you the changes, etc). Now, when you do a git log
you see them, but when you say git log that.file
these commits don't show up? This is for you.
The reason is that the file got deleted deleted/re-added/renamed (any or all of those).
Instead of ...
git log master -- some.file
... you need to say:
git log --follow master -- some.file
Then your commits will show up.
Note that tig
also understands --follow
.
Kudos to Julien...
How to revert features for deployment, merge back, and how to stay sane
Removing features and merging those changes back can be painful. Here is how it worked for me.\
tl;dr: Before merging back: reinstate reverted features in a temporary branch, then merge that branch.
Scenario
Consider your team has been working on several features in a branch, made many changes over time and thus several commits for each feature.\
Now your client wants you to deploy while there are still stories that were rejected previously and can't be deployed.
...
How to print Github wiki pages
I have no idea how it's supposed to work (or why the don't have a print CSS), but this works for pages written with Markdown:
- "Edit" the wiki page
- Copy all text
- Run a Markdown interpreter and pipe its result, e.g.:
kramdown > /tmp/github.html
- Paste your markdown
- Press Ctrl-D to finalize your input
- Open the generated HTML file and print it.
O_o
Improved gitpt now part of geordi
Our gitpt
script to generate git commits from Pivotal Tracker stories has been tweaked and polished and is now part of the geordi gem.
Install the freshly released version 0.7 now:
gem install geordi
This update will bring you commit
with an initial "setup wizard" (that asks for your PT API key and initials) and prettier output: stories are colored by their state and thos...
monperrus/ExpandAnimations - GitHub
ExpandAnimations is a LibreOffice/OpenOffice.org Impress extension to expand presentation animations before exporting to PDF. This way the exported PDF will have one page per animation stage.
tanoku/redcarpet - GitHub
Ruby bindings for Sundown, a fast and full-featured Markdown parser that lets you define renders for arbitrary output formats.
davetron5000/methadone - GitHub
Framework to write command-line apps in Ruby. Comes with a nice way of processing parameter options, some utility classes and Cucumber steps for testing your CLI app.
Git instaweb
Git has a built-in repository viewer for your web browser. a bit similar (but less awesome) than github.
If you have apache installed, simply go to your repository, and enter
git instaweb --httpd apache2
otherwise, simply install lighttpd
and just run
git instaweb
This should open a brower automatically pointing to your repository. If not, try to connect to localhost:1234
.
You can stop the server with
git instaweb --stop
How to ignore new files or changed files in git
How to ignore new files
Globally
Add the path(s) to your file(s) which you would like to ignore to your .gitignore
file (and commit them). These file entries will also apply to others checking out the repo.
Locally
Add the path(s) to your file(s) which you would like to ignore to your .git/info/exclude
file. These file entries will only apply to your local working copy.
How to ignore changed files (temporarily)
In order to ignore changed files to being listed...
See with tig which git commits touch a file or files or folders
tig path_to_file_or_files_or_path_with_wildcard
Rails 3.1 error message: Could not find a JavaScript runtime
After starting the Rails server in a freshly generated Rails 3.1 project you could see an error message such as
/usr/lib/ruby/gems/1.8/gems/execjs-1.3.0/lib/execjs/runtimes.rb:50:in `autodetect': Could not find a JavaScript runtime. See https://github.com/sstephenson/execjs for a list of available runtimes. (ExecJS::RuntimeUnavailable)
Just add a JavaScript runtime to your Gemfile and the error vanishes.
Examples:
gem 'therubyracer'
gem 'extjs'
Creating a patch in git and how to apply patches
You can convert git commits into patch files. Those can be used to apply to a different repository [1] or by someone else (e.g. sent when sent to them via e-mail).
Creating a patch in git
- Make your changes and commit them.
- Run
git format-patch COMMIT_REFERENCE
to convert all commits since the referenced commit (not including it) into patch files.
For example, let's say you prepared 2 commits. Run:
git format-patch HEAD~~
This will create 2 files, one for each commit since HEAD~~
, like these:
00...