How to change the mouse pointer in Xfce

Unlike in Gnome, there is no graphical tool to set a mouse cursor in Xfce. Run this on a terminal instead:

sudo update-alternatives --config x-cursor-theme

You need to sign out and back in for your changes to have an effect.

imgAreaSelect - image selection/cropping jQuery plugin

imgAreaSelect is a jQuery plugin for selecting a rectangular area of an image. It allows web developers to easily implement image cropping functionality, as well as other user interface features, such as photo notes (like those on Flickr).

Freetile.js

Freetile is a plugin for jQue­ry that en­ables the or­ganiza­tion of web­page con­tent in an ef­ficient, dynamic and re­spon­sive layout. It can be applied to a con­tain­er ele­ment and it will at­tempt to ar­range it's childr­en in a layout that makes opt­im­al use of scre­en space, by "pack­ing" them in a tight ar­range­ment

Zeus promises to make rails development faster

I am talking about development speed. When your application starts growing and you start adding gems, it starts to take really long to start up, be it the server, console or just running a single spec.

Zeus is smart, you don’t have to put it in your Gemfile or run it with Bundler, all you need to do is create a JSON config file via zeus init and then start the server zeus start.

After that, you’re ready to go, all you need to do is prefix every command with zeus. That means rails server becomes zeus server, `rails console...

A jQuery plugin for producing bar charts from tables.

As the title says: this jQuery plugin creates bar charts from HTML tables. It comes in some different flavors.

Check the examples page: http://alphagov.github.com/magna-charta/.

Capybara 2.0 has been released

The gem author Jonas Nicklas highlights in a Google Groups post that the release

  • is not backwards compatible to 1.x versions of Capybara
  • does not support Ruby 1.8.x anymore
  • removes confusion with Rails' built in integration tests (you put capybara rspec integration tests into the spec/feature/... folder) and the :type metadata has been changed from :request to :feature
  • throws exceptions when trying to interact with an element whose identifier is...

Andand and SimpleDelegator

The very useful andand gem does not play very nice with Ruby's SimpleDelegator (or vice versa).

This following will not work:

class MyDecorator < SimpleDelegator
  def foo
  end
end

MyDecorator.new(Object.new).andand.foo

The reasons are a bit subtle, basically SimpleDelegator will "force" some methods to be delegated, so the andand method is called on the wrapped object, not the delegator.

You can fix it like this:

class Decorator < SimpleDelegator
  def an...

Using sets for many-to-many relationships

A technique to vastly reduce the number of join model records that need to be stored in the database.

The technique is only effective when there is a high redundancy in your data, e.g. combinations of the same 20 tags are used to label thousands of books.

The technique is also limited in that your join models cannot have additional logic, such as attributes or callbacks.

Ther has-many-with-set gem is an implementation of this technique.

uninitialized constant MysqlCompat::MysqlRes (NameError)

If you get a stacktrace complaining about uninitialized constant MysqlCompat::MysqlRes a system library update might broke your gem.

You might have switched from MySQL to MariaDB, but forgot to rebuild your MySQL gems.

Try fully removing and re-installing the gem:

gem uninstall mysql mysql2
bundle install

Xfce: How to change the default program for a file extension

This is super stupid:

  • In the Thunar file manager, select the file
  • Go to File / Properties / Open With (WTF!)
  • Select the preferred application from the list and hit "Set default"

This setting will apply to all files with that extension.

How to move a window to the next monitor on Xfce, Mate and other X Window Managers

Since I use this a lot in my daily work and there were no scripts working properly for me, I made one myself.
It's actually not bound to Xfce but should work on any window manager (haven't tried it, though).

Installation

  1. If you don't yet have xdotool, install it:

    sudo apt-get install xdotool
    
  2. If you don't yet have wmctrl, install it:

    sudo apt-get install wmctrl
    
  3. Store the attached file in some place that's in your PATH.
    The cool kids use ~/bin/.

  4. Make it executable: `chmod +x ~/bin/move-to-next-mo...

Setup an Ubuntu mirror that enables local release upgrades

Setup the mirror by following the steps described here.

If you want to enable OS upgrades using do-release-upgrade make sure you include $release-proposed packages in the mirror script, e.g., precise-proposed. Additionally, you have to add main/dist-upgrader-all to the $section in your script as debmirror silently ignores some directories.

I attached our modified script to include current releases

Enable Ubuntu release upgrade from the local mirror
--------------------------------------...

How to set the default monospace font on Xfce (Xubuntu)

While you can set your own font in your terminal or other tools, it will not change the default "Monospace" font that some applications use.

To change that, edit ~/.fonts.conf and add settings for the "monospace" family. Here is how it looks on my machine now:

<fontconfig>
  <match target="pattern">
    <test qual="any" name="family">
      <string>monospace</string>
    </test>
    <edit name="family" mode="assign">
      <string>DejaVu Sans Mono</string>
    </edit>
  </match>
</fontconfig>
...

CSS: Vertically center with display: table-cell

The classical scenario: There's a parent div element and you want to center some arbitrary child element vertically inside of it. Here's how you do it (also try this jsfiddle).

The children need to be block elements.

The HTML

<div class="parent">
  <div class="child"></div>
  <div class="child"></div>
  ...
</div>

The CSS

.parent {
  display: table-cell;
  vertical-align: middle;
  width: 500px;
  height: 300px;
}
      
.child {}

When .child elements are inline elements, add `display: bl...

Carrierwave: Auto-rotate tagged JPEGs

Modern cameras often produce JPEGs that have a "I should be rotated 90° to the left" flag. If you process such pictures using Carrierwave this will be ignored and you'll end up with a wrongly rotated image.

Fortunately, this is easy to fix:

In your Uploader, add

process :auto_orient # this should go before all other "process" steps

def auto_orient
  manipulate! do |image|
    image.tap(&:auto_orient)
  end
end

Note: You can add the process :auto_orient outside of all your version blocks and it will apply...

Writing Fast, Memory-Efficient JavaScript

JavaScript engines such as Google’s V8 (Chrome, Node) are specifically designed for the fast execution of large JavaScript applications. As you develop, if you care about memory usage and performance, you should be aware of some of what’s going on in your user’s browser’s JavaScript engine behind the scenes.

Rubygems: Rebuild native extensions

Rarely, you might want to rebuild all gems with native extensions, because they might be compiled against outdated system libraries, resulting in some warnings or even segfaults or other ruby errors.

You can do that using

gem pristine --all

This will reset all gems to a pristine state as if you'd reinstall them, and as a side effect, rebuild all native extensions.

The above command will also help you sorting out errors like this after a distribution upgrade:

libmysqlclient_r.so.16: cannot open shared object file: No such fil...

query_diet now support Rails 3

Installation differs slightly from older versions, please check the README.

Get all associations of an ActiveRecord class

YourClass.reflect_on_all_associations.map(&:name)

Get the class name by calling class_name, or the type of the association (belongs_to, has_many,...) by calling macro

Subtle Patterns Preview

Ever wanted to preview a pattern from Subtle Patterns on your site without the hassle of swapping out images and modifying CSS?

Subtle Patterns Preview provides a simpler way to do it.

Keyboard Navigation Plugin for Safari, Chrome and Firefox with a rich feature set

gleeBox is an experimental project that takes a keyboard-centric approach to navigating the web. It provides alternatives to actions that are traditionally performed via the mouse. Some of these are radically more efficient than using a mouse, some not so much. In all cases, they are mostly meant for keyboard and command line lovers.

Gleebox is a terrific plugin that makes navigating through webpages a wink. It even allows for selecting by jQuery selector.

Taming icon fonts for use in Rails views

Icon fonts like Font Awesome are infinitely scalable, look great on high-DPI displays and will give your app a modern look.

However, icon fonts can be very awkward to use compared to raster icons. Elements are given icons by giving them a special class like icon-plus or icon-home:

<span class="icon-plus">Create</span>

The icon font's stylesheet will then recognize this class and insert the icon as the element's :before style.

In practic...

Internet Explorer will download CSS files twice, if referenced via scheme-less URLs

You can use scheme-less URLs (or protocol-relative URLs) to have browsers use the current protocol (HTTP or HTTPS) when loading content referenced with such an URL.

A protocol relative URL doesn’t contain a protocol. For example, http://stevesouders.com/images/book-84x110.jpg becomes //stevesouders.com/images/book-84x110.jpg

Browsers substitute the protocol of the page itself for the resource’s missing protocol. Problem solved!

But:

Internet Explorer 7 & 8 will download st...

Firefox: Inspecting mixed content warnings (and how to enable them)

Having your site run on SSL is worthless when you include content over an unsafe connection (HTTP).

Here is how to hunt down mixed content with Firefox.

How to enable mixed content alerts

If your Firefox does not warn you about mixed content on pages (mine did not), you can enable it again:

Visit about:config and search for security.warn_viewing_mixed. If it's set to false, set it back to true again.

Seeing which URLs are fetched from unsecured connections

Firefox 16+ will show you mixed content in its "Web Console".
Open it ...