Search_spinner Cross_grey Magnifier
help

Search syntax

  • Search for repeating cards with repeats:yes
  • Search for unfinished cards with unfinished:yes
  • Search for cards in a certain topic with topic:"name"
  • Search for phrases with "a phrase"
  • Exclude a word from search: -word
  • Exclude a phrase from search: -"a phrase"
  • Exclude a topic from search: -topic:"name"

Why your javascripts should be executed after the dom has been loaded

Most of the JavaScript snippets have code that manipulates the DOM. For that reason dom manipulating javascript code should have been executed after the DOM has loaded completely. That means when the browser has finished HTML parsing and built the DOM tree. At that time, you can manipualte the DOM although not all resources (like images) are fully loaded.

The following snippets show how you can do this with plain JavaScript, jquery or prototype ([dom ready …

How to combine greps on log files opened with tail -f

In order to chain greps on log files that are opened via tail -f test.log you have to use the --line-buffered command line option for grep.

Imagine you have the following content in your log file.

# content for log/test.log
test foo
bar
test foo bar baz
bla

Now if you would like to grep for lines that contain foo but not bar, you can use the following command chain:

$ tail -f log/test.log | grep --line-buffered "foo" | grep -v "bar"

Output:
test foo    

How to create Excel sheets with spreadsheet gem and use number formats for cells like money or date

The following snippet demonstrates how you could create excel files (with spreadsheet gem) and format columns so that they follow a specific number format like currencies or dates do.

require 'rubygems'
require 'spreadsheet'

Spreadsheet.client_encoding = 'UTF-8'

book = Spreadsheet::Workbook.new
sheet1 = book.create_worksheet :name => 'test'

money_format = Spreadsheet::Format.new :number_format => "#,##0.00 [$€-407]"
date_format = Spreadsheet::Format.new :num...
External content

HTML5 Please: Use the new and shiny responsibly

Look up HTML5 features, know if they are ready for use, and if so find out you should use them – with polyfills, fallbacks or as they are.

External content

marcandre/backports - GitHub

Gem to get Ruby 1.9 features in Ruby 1.8.

External content

jQuery UI Bootstrap

Twitter's Bootstrap CSS blueprint as a jQuery UI theme. Even if you don't want to use Bootstrap as a CSS framework, this theme looks better than jQuery UI's default theme.

Git: Move 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 ~).
This will create a .patch file that describes this commit.

Apply the patch

In the target repository, apply the patch with
git apply PATH_TO_PATCH

If the patch does not apply cleanly, git will not do anything. I…

Git: Diff staged changes

Saying git diff only shows unstaged changes against HEAD (or any hash or branch you supplied) but leaves out files you already staged for the next commit.

To diff your added changes, 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
 ...

Enabling view rendering for controller specs

Views are normally (for good reason) not rendered in controller specs. If you need it to happen, use:

RSpec 1 (Rails 2):
integrate_views
RSpec 2 (Rails 3):
render_views

Note that you can't use that inside it blocks but need to put it in the nesting example group, like this:

describe '#update' do
  context 'when ren...
External content

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.

New geordi script: migrate-all

Use the command geordi migrate-all to migrate your databases and to prepare them before running tests. The abbrevation geordi m works as well.

  • It will run power-rake db:migrate if parallel_tests does not exist in your Gemfile
  • Otherwise it runs b rake db:migrate and then executes b rake parallel:prepare if parallel_tests was found in your Gemfile.

Associations named using a string cannot be included in a scope

If you defined your association via

class Article
  belongs_to "category"
end

and you try

Article.scoped(:include => :category)

you will get an error message

in `preload_one_association': Association named 'category' was not found; perhaps you misspelled it? (ActiveRecord::ConfigurationError)

Solution

Always define your assocations via symbol

class Article
  belongs_to :category
end  

Opening images with 100% zoom in Photoshop

You want Photoshop to always open files with "full" (100%) zoom and not try to fit them to your screen?
Tough luck – there is no setting for this.

But, after opening the file, you can zoom to 100% by:

  • pressing Ctrl-Alt-0 (on Windows; for Mac it's Meta-Alt-0)
  • or double-clicking the magnifier tool icon.

External content

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.

How to install a specific version of RubyGems (and how to downgrade)

Sometimes you want one distinct version of RubyGems to be installed to replicate the same behavior across multiple servers.

Usually would do this to update your RubyGems, but this always takes you to the latest version:

gem update --system

While there are ways around the interwebs that use the rubygems-update package and call its setup.rb, there is an undocumented switch you can use:

gem update --system 1.3.7

This updates to the given version, 1.3.7 in the above case, by walking the rubygems-update package way itself.

—…

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…

2886 cards