SearchableTrait is now a gem: Dusen
For two years we've been using SearchableTrait
which gives models the ability to process Googlesque queries like this:
Contact.search('a mix of words "and phrases" and qualified:fields')
This trait used to be a huge blob of code without tests and documentation, so I made a gem out of it. Check out https://github.com/makandra/dusen for code, tests, and a huge README.
You should use the Dusen gem and delete SearchableTrait
in all future projects.
Note that the syntax to define query proc...
How to fix: Unable to read files from a VirtualBox shared host folder
When you want to copy/move from a shared folder (on Windows guests, for example) and it fails with absurd error messages (lots of text or an error about the target being read-only), you are probably running on Guest Additions that no longer match your VirtualBox version.
Fix: install the latest VirtualBox Guest Additions in your guest machine.
Note that you need to make sure you are using the correct ISO.
How to fix: VirtualBox Guest Additions setup is out of date
When you are trying to install/update VirtualBox Guest Additions on your guest machine but the setup is for a different/older version (for example 4.0.4 tools for a 4.1.x VirtualBox installation), try this:
sudo apt-get install virtualbox-guest-additions-iso
For some reason, this is no dependency to VirtualBox itself -- and if you have an old ISO lying around, VirtualBox will just pick that one, regardless of its version.
Oh joy.
Xfce: Classic panel layout in the style of Gnome 2 or Windows XP
Xfce gives you a million options to configure your panels. Together with Xfce's sometimes arcane configuration UI, this can be a huge time waster and super-annoying if you need to get work done the same day.
This card describes how to setup a classic panel layout as you might be used to from Gnome 2 or Windows (see screenshot below). You can use this to quickly get productive in Xfce, and as a starting point for further customization.
- [One task bar on the bottom of each monitor](https://makandracards.com/makandra/...
Xfce: Configure global keyboard shotcuts
Global keyboard shortcuts can be configured in two separate panels in the Xfce Settings manager:
- Shortcuts related to managing windows (e.g. "Show Desktop" or "Switch to Workspace 2") are unter Window Manager / Keyboard
- Shortcuts to launch applications (e.g. Meta+T for Terminator) are under Keyboard / Application Shortcuts
When Nautilus/Thunar file manager sorts case-sensitively
When your file manager sorts file case-sensitively after a distribution upgrade, you probably need to reconfigure your locale settings as described here.
Switch from Compiz to Xfce's native window manager
If you tried out Compiz on top of Xfce and found it to be a world of pain like me, you can get to Xfce's native window manager by saying:
xfwm4 --replace
Ubuntu: Fix missing sound after a version upgrade
If you can now longer hear or record sounds after upgrading Ubuntu, you probably need to re-tell Ubuntu which devices to use for playback/recording.
Fix sound output
- Open the PulseAudio Volume Control (
pavucontrol
). If you don't have that application, install it withsudo apt-get install pavucontrol
. - Start playback of an MP3 so you can see when changes take effect.
- Under "Output devices" use the "Mute" buttons to figure our which output device is the correct one. When you found it, also set it as the fallback dev...
Xfce: Separate task bars for each monitor
So you have multiple screens under Xfce and want to have one task bar on each screen, only showing applications on that screen. Here you go:
- Create one panel for each monitor. Panels can be created from the panel preferences of another panel (yeah...).
- Unlock each panel by going to Right click / Panel / Panel preferences... and uncheck "Lock panel". You now see a grip that you can use to drag one panel to the bottom of each monitor.
- Again go into the panel preferences, and under Items add a single item "Window buttons". In the ite...
Xfce: Configure multiple monitors
If you don't want to mess around with arcane incantations inside xorg.conf
, you can use the graphical arandr
tool:
sudo apt-get install arandr
arandr
If all your monitors are stacked in the same space, the space is not wide enough and you can't really move them, you need to switch to a proprietary driver. If it works with the open source driver for you, do not bother using another one.
For ATI cards:
- install
fglrx
andfglrx-amdcccle
- reboot
- run the ATI configuration tool (
amdcccle
; if the binary is unavailable ...
Xfce: Take a screenshot with the "Print" key
- Go to Settings Manager / Keyboard / Application Shortcuts
- Add a shortcut for the Print key that calls
xfce4-screenshooter -f
This may be configured for you by default.
Rails 2: Calling instance_eval on a scope will trigger a database query
In Rails 2, when calling instance_eval
or instance_exec
on a scope, the scope will fetch its records from the database.
This has been fixed in Rails 3+.
How to find out a pixel's transparency with Gimp
If you have a PNG and want to know a pixel's alpha channel value, you can use Gimp:
- Use the color picker tool
- Hold the
Shift
key while clicking the pixel
A window will appear, containing color information, including the alpha channel.
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 jQuery that enables the organization of webpage content in an efficient, dynamic and responsive layout. It can be applied to a container element and it will attempt to arrange it's children in a layout that makes optimal use of screen space, by "packing" them in a tight arrangement
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 serverzeus start
.
After that, you’re ready to go, all you need to do is prefix every command with zeus. That means
rails server
becomeszeus 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
-
If you don't yet have
xdotool
, install it:sudo apt-get install xdotool
-
If you don't yet have
wmctrl
, install it:sudo apt-get install wmctrl
-
Store the attached file in some place that's in your
PATH
.
The cool kids use~/bin/
. -
Make it executable: `chmod +x ~/bin/move-to-next-mo...