Search_spinner

Sharing cookies across subdomains with Rails 3

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

  MyApp::Application.config.session_store(
    :cookie_store,
    {
      :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

As :domain => :all is set in Rails 3, local session cookies seem not to be set unless you specify a top-level…

External content

Web Typography for non-designers - Presslabs

Great crash course into basics and common mistakes.

Auto-destruct in 56 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.

An auto-mapper for BEM classes in Cucumber selectors

When you are using the #selector_for helper in Cucumber steps, as e.g. Spreewald does, the following snippet will save you typing. It recognizes a prose BEM-style selector and maps it to the corresponding BEM class.

Examples

"the main menu" -> '.main-menu'
"the item box's header" -> '.item-box--header'

Code

Save this to features/support/selectors.rb, or update your file:

```
module HtmlSelectorsHelpers
def selector_for(locator)
case locator

# Auto-mapper for BEM class...
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…
Repeats

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.

Ruby: Counting occurrences of an item in an array / enumerable

Enumerable#count can do three things.

  • With no argument provided, it returns the number of items.
  • With an argument, it returns the number of items matching the given value.
  • With a block, it counts the number of elements yielding a truthy value.
ary = [1, 2, 4, 2]
ary.count #=> 4
ary.count(2) #=> 2
ary.count { |x| x % 2 == 0 } #=> 3
Auto-destruct in 59 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”
Repeats

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:

app/assets/fonts
app/assets/images
app/assets/javascripts
app/assets/stylesheets

External content

Using PostgreSQL and jsonb with Ruby on Rails

Postgres 9.4 introduces a new column type: jsonb. json and jsonb columns store data differently, so just compare the two when you want to store JSON data and choose the one that matches your use case best.

Rails 4.2 includes support for jsonb columns, too. The article outlines different ways on how to interact with the serialized object.

Ruby: Flatten arrays by only one level

Array#flatten by default flattens an array recursively. To only flatten the array for e.g. one level, it takes an optional argument.

# Flattens the array recursively
>> [1, [2, [3]]].flatten
=> [1, 2, 3]

# Flattens the array the given number of times
>> [1, [2, [3]]].flatten(1)
=> [1, 2, [3]]
2727 cards