SQL: Find out number of rows of all tables within a MySQL database

Here you are:

SELECT table_name, table_rows FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = 'your_database' order by table_rows;

Protected and Private Methods in Ruby

In Ruby, the meaning of protected and private is different from other languages like Java. (They don’t hide methods from inheriting classes.)


Private methods can only be called with implicit receiver. As soon as you specify a receiver, let it only be self, your call will be rejected.

class A
  def public_method
  def other_public_method
  def private_method
    "I'm private"
Auto-destruct in 56 days

Updated: How to coordinate distributed work with MySQL's GET_LOCK

Thomas K. found a Rubygem implementation that implements the technique. You should be able to use it in lieu of our old-school Lock model.

External content

Have a Rails 2 app? You can run it on the newest Ruby!

A 12 step guide to get a rails 2.3.18 app boot up in modern Rubies.

Remove URLs from the Google index

Obviously, you only can do this for your own sites.
You need to authenticate a domain you want to remove content from via Webmaster Tools.

To remove a URL:

  1. Open Webmaster Tools
  2. Select the respective site from the list of domains under your control
  3. Choose “Google Index” from the menu left
  4. Click “Remove URL”

Rails asset pipeline: Why things break in production and what precompilation does to your assets

When you work with a Rails 3.1+ application, you will be working with the asset pipeline. The asset pipeline is awesome until you deploy. Then it will be distinctly less awesome if you haven’t done everything as the pipeline expected it from you.

The problem

When using the asset pipeline your assets (images, javascripts, stylesheets, fonts) live in folders inside app:



Use a global .gitignore file to ignore stuff from your machine

Sometimes you want git to ignore certain files that appear on your machine. You can do this in 3 ways:

  • Per project, in the project’s .gitignore file
  • Per project, in a local exclude file
  • Globally on your machine

Downsides of per-project .gitignore entries

While it might be tempting to set it per project (other devs might benefit from it), you

  • need to do it each time for every project
  • “pollute” a project’s .gitignore file with stuff…

Sharing cookies across subdomains with Rails 3

To achieve this goal you have to setup the session store like the following example:

      :key => '_myapp_session',
      :domain => :all, # :all defaults to da tld length of 1, '.web' has length of 1
      :tld_length => 2 # Top Level Domain (tld) length -> '*.myapp.web' has a length of 2

The invconvenient side effect for local development

… or: Why do I get “Can’t verify CSRF token authenticity” even if csrf toke in present?

As :domain => :all

External content

Web Typography for non-designers - Presslabs

Great crash course into basics and common mistakes.

Auto-destruct in 53 days

Updated: Block formatting contexts

Yesterday I tried every block-formatting-context-creating property
and found that only overflow: hidden is usable. Added info why
each other property will not be working.

External contentRepeats

Compiling Javascript template functions with the asset pipeline

The asset pipeline (which is actually backed by sprockets) has a nice feature where templates ending in .jst are compiled into Javascript template functions. These templates can be rendered by calling JST['path/to/template'](template: 'variables'):

<!-- templates/hello.jst.ejs -->
<div>Hello, <span><%= name %></span>!</div>

// application.js
//= require templates/hello
$("#hello").html(JST["templates/hello"]({ name: "Sam" }));

Whatever is in the <% ... %> is evaluated in Javascript…

Carrierwave: Efficiently converting images

When uploading images, adding more than one process to a version can cause MiniMagick to run multiple commands. In order to have all processing done in one mogrify system call, you’ll need to define only one process that combines all options you’d like to pass in.


Pitfall: ActiveRecord callbacks: Method call with several conditions

In the following example the method update_offices_people_count won’t be called when office_id changes, because it gets overwritten by the second line:

after_save :update_offices_people_count, :if => :office_id_changed? # is overwritten
after_save :update_offices_people_count, :if => :trashed_changed?

Instead write:

after_save :update_offices_people_count, :if => :office_people_count_needs_update?

def office_people_count_needs_update?
  office_id_changed? or trashed_changed?
External content

Markdown Live Preview

An online markdown live previewer with GitHub Flavoured Markdown support.
Another online markdown live previewer with GitHub Flavoured Markdown support.
An online markdown live previewer without GitHub Flavoured Markdown support.

How to create memory leaks in jQuery 1.x

Note that the information in this card only pertains to jQuery 1.x. jQuery 2 does not have a global $.cache. The issues in this card are probably one of the main reasons why jQuery 2 broke browser compatibility and only supports IE 9+.

jQuery 1.x doesn’t store information about event listeners and data values with the element itself. This information is instead stored in the global $.cache object. Every time you add an event listener or data value to a jQuery object, $.cache gains another entry.

**The only way…

How to create giant memory leaks in AngularJS

This guide shows how to create an AngularJS application that consumes more and more memory until, eventually, the browser process crashes on your users.

How to observe memory consumption

To inspect the amount of memory consumed by your Javascripts in Chrome:

  • Open an incognito window
  • Open the page you want to inspect
  • Press Shift + ESC to see a list of Chrome processes
  • Find the process for the incognito window
  • Right-click on the list and check Javascript memory
  • Observe the *Javascript memor…

How to make your application assets cachable in Rails

Every page in your application uses many assets, such as images, javascripts and stylesheets. Without your intervention, the browser will request these assets again and again on every request. There is no magic in Rails that gives you automatic caching for assets. In fact, if you haven’t been paying attention to this, your application is probably broken in that respect and users will re-request every single image etc. on every page load.

While ETags will usually prevent the image d…

External content

How to coordinate distributed work with MySQL's GET_LOCK · Xaprb

This article explains how I replaced file-based methods to ensure only one running instance of a program with MySQL’s GET_LOCK function. The result is mutual exclusivity that works in a distributed environment, and it’s dead simple to implement.

How to get a database-wide lock without creating table rows.

An implementation in a Rubygem seems to be with_advisory_lock.

2728 cards