How to change the font in Sublime Text 2
Open up your "Base File.sublime-settings
" (Preferences Menu → File Settings – User) in Sublime Text 2. Add entries for font_face
, and optionally font_size
, so it looks similar to this:
{
"font_face": "Envy Code R",
"font_size": 11.5
}
Cool: when you save the configuration file, changes will be applied instantly.
Solve issues with Samsung TV as computer screen
We have a big flat screen TV (Samsung LE46c650l1kxxu) in our conference room. Configuring it properly, we were encountering some issues.
This is a list of issues, providing a solution to each.
No sound with DVI/HDMI and separate audio
There are some inputs on the side of the TV. These will not work for split video and audio.
On the back are more inputs you might not have seen. Choose HDMI/DVI as video in and Audio in for HDMI/DVI as audio in. Do not use RCA audio input but the [...
Create RAID on Amazon EC2 EBS volumes
If you use Amazon AWS cloud services you definitively want to utilize software raid for IO intensive stuff such as database data directories and the like.
Here's how you create it:
- Create some EBS volumes within management console or
sudo mdadm --create -f /dev/md0 --chunk=256 --level 10 --raid-devices 4 /dev/sdf /dev/sdg /dev/sdh /dev/sdi
- Create a fs on
/dev/md0
using mkfs*-tools - As soon as this is running, you should do that:
sudo mdadm --detail --scan >> /etc/mdadm/mdadm.conf
Make sure the last line in `/etc/mdadm/md...
Marry Date::Performance and Spreadsheet gems
Date::Performance is a gem that replaces various method in Ruby's Date
class with fast C implementations. Unfortunately it doesn't fully implement an internal method (Date.ajd_to_jd
) which makes your code blow up when you use it together with the Spreadsheet gem.
A solution is to restore the Ruby implementation of this particular method. To do this, copy the attached file to lib/fix_date_performance.rb
to config/initializers
.
How to: Store multiple Vim commands in macros and recall them
Vim allows recording a batch of commands as a macro. This is handy if you need to do the same things over and over.
Here is how:
- Press
q
to enter macro mode. - Press a letter (not a number!) key to assign a slot to your macro.
- You are now recording. Do whatever you want with usual commands.
- Once you are done, press
q
again to stop recording. - You can now run your recorded macro by pressing
@
and its assigned letter key.
Cheats:
- If you want to run a macro repeatedly, type a number before pressing the
@
key. Example: ...
Always store your Paperclip attachments in a separate folder per environment
tl;dr: Always have your attachment path start with :rails_root/storage/#{Rails.env}#{ENV['RAILS_TEST_NUMBER']}/
.
The directory where you save your Paperclip attachments should not look like this:
storage/photos/1/...
storage/photos/2/...
storage/photos/3/...
storage/attachments/1/...
storage/attachments/2/...
The problem with this is that multiple environments (at least development
and test
) will share the same directory structure. This will cause you pain eventually. Files will get overwritten and...
How to grep through the DOM using the Capybara API
When your Cucumber feature needs to browse the page HTML, and you are not sure how to express your query as a clever CSS or XPath expression, there is another way: You can use all
and find
to grep through the DOM and then perform your search in plain Ruby.
Here is an example for this technique:
Then /^I should see an image with the file...
How to look at hidden X screens
When you have a program running in a hidden X screen (like with Xvfb for Selenium tests) you may want to look at that hidden screen occasionally.
First, find out what X displays are currently active:
netstat -nlp | grep X11
This should give you some results like these:
unix 2 [ ACC ] STREAM LISTENING 8029600 4086/Xvfb /tmp/.X11-unix/X99
unix 2 [ ACC ] STREAM LISTENING 8616 - ...
A few hints when upgrading to Ruby 1.9
Note: If you are currently working with Ruby 1.8.7 or 1.9.3, we recommend to upgrade to Ruby 2.1 first. From our experience this upgrade is much smoother than the jump from 2.1 and 2.2, while still giving your the huge performance gains of Ruby 2. Also, if you're on Ruby 1.8.7, we recommend to skip a troublesome upgrade to 1.9.3 and go straight to 2.1.
When trying to make a Rails app run on Ruby 1.9, you're likely to encounter several issues. Here are a few solutions (obviously not exhaustive):
When running `bundle ...
Rails 3: Sending tempfiles for download
When you create a temporary file (e.g. to store a generated Excel sheet) and try to send it to the browser from a controller, it won't work by default. Take this controller action:
class FoosController < ApplicationController
def download
file = Tempfile.new('foo')
file.puts 'foo'
file.close
send_file file.path
end
end
Accessing this controller action will usually raise a 404 not found in the browser and the Apache log will say:
The given path was above the root path: xsendfile: ...
Virtual attributes for date fields
Note that this card is very old. You might want to use ActiveType for your auto-coerced virtual attributes instead.
We sometimes give our models virtual attributes for values that don't need to be stored permanently.
When such a virtual attribute should contain Date
values you might get unexpected behavior with forms, because every param is a string and you don't get the magic type casting that ...
Running the Awesome window manager within Gnome
Note: Consider using MATE instead of Gnome 3 on newer system
Awesome is a very good tiling window manager that provides neat features like automatic layouting of windows, good multi-display support with per display workspaces and more. Unfortunately, it is only a window manager, and lacks a lot of Gnome's conveniences like the network manager, application menus, automatic updates etc.
Fortunately, Gnome allows you to selectively replace only the win...
Show the status of a running dd copy
When you do a bitwise copy using the dd
tool you will not see any output until it completes or an error occurs.
However, you can send a command signal to the process to have it show its progress so far.
From another terminal, simply call (be root or use sudo
):
pkill -USR1 dd
This makes dd
write something like this into the terminal it is running in:
388+0 records in
387+0 records out
396288000 bytes (396 MB) copied, 24.9862s, 15.9 MB/s
You may also pass the status=progress
option to dd
like so:
dd if=... o...
Disable Dell U2410 beeping sound
The first thing to do with any new U2410 should be to disable the incredibly annoying beep when pressing any monitor button. Here is the fastest way to achieve that:
- OSD button (above the power button)
- Menu
- 2 × Up (You should be at “Other Settings” now)
- Right
- 4 × Up (“Button Sound”; the “Power Save Audio” entry is usually grayed out, so this is 1 beep less than from above.)
- Right
- Down
- Tick
Do it this way or your colleagues will stand at your desk after the 12th beep, ready to smack you.
Popular mistakes when using nested forms
Here are some popular mistakes when using nested forms:
- You are using
fields_for
instead ofform.fields_for
. - You forgot to use
accepts_nested_attributes
in the containing model. Rails won't complain, but nothing will work. In particular,nested_form.object
will benil
. - The
:reject_if
option lambda in youraccepts_nested_attributes
call is defined incorrectly. Raise the attributes hash given to your:reject_if
lambda to see if it looks like you expect. - If you are nesting forms into nested forms, each model involved ne...
Check whether an element is visible or hidden with Javascript
jQuery
You can say:
$(element).is(':visible')
and
$(element).is(':hidden')
jQuery considers an element to be visible if it consumes space in the document. For most purposes, this is exactly what you want.
Native DOM API
Emulate jQuery's implementation :
element.offsetWidth > 0 && element.offsetHeight > 0;
jQuery > 3
Query 3 slightly modifies the meaning of :visible (and therefore of :hidden).
Emulate jQuery'...
Be careful when closing expanded stories in Pivotal Tracker
When you open up a story to only have a look at it, close it by pressing the "Cancel" button (or Esc key).
Clicking the arrow in the top left is the same as pressing the "Save" button. If someone changes the story description in the meantime you will overwrite their changes with everything you see, even if you did not change anything. If you only want to take a peek, prefer to hover the speech bubble icon.
If your story gets shotgunned and you notice it, you are lucky -- and you may be able to get your changes back. Open up the his...
How to build the perfect number of blank records for a nested form
When you render a nested form for a Movie
which has_many :actors
, you want to render the right number of blank Actor
forms. The right number means:
- A minimum number of blank forms so the user can add more
Actors
to an existingMovie
, e.g. 2. - A minimum total number of forms (both blank and pre-filled) so the user sees more than just 2 blank
Actor
forms when she is enteringActors
for the first time, e.g. 5.
For the example above, this is the desired progression of the number of blank forms:
| Number of actors | Number of ...
mysqltuner.pl
This Perl script will run diagnostics on your MySQL database and recommend changes to your MySQL configuration.
How to upgrade RubyMine
This card explains how to upgrade an existing RubyMine installation to a newer version. If you're installing RubyMine for the first time, see install RubyMine under Ubuntu. You might also consider installing RubyMine with snap, so it can receive automatic updates (also described in the install card).
This procedure ensures that an update does not totally break your IDE, as it allows you to keep both the previous and the new version of RubyMine:
- [Download the newest version](http://www.jetbrains.com/ruby...
Order in which RSpec processes .rb files
Because your examples should not change global state, you should not need to care about the order in which RSpec processes your .rb
files. However, in some cases you might want to know.
RSpec 3
- Runs
.rb
files in alphabetical order of their file paths by default (or when you specify--order defined
). - You run t...
New Cucumber Factory makes it easier to associate records
I pushed a new version of the Cucumber Factory gem. This new release lets you refer to a previously created record by any string attribute:
Given there is a movie with the title "Before Sunrise"
And there is a movie with the title "Limitless"
And there is a movie with the prequel "Before Sunrise"
Note how we didn't have to explicitly give the prequel a name in the example above. This is still possible, but will rarely be necessary now:
Given "Before Sunrise" is a movie with...
Dynamically skip Capistrano hooks
When you have a hook in your Capistrano file that dumps your remote database, you might not want it to dump each time you deploy (say, you're experimenting with staging
and don't want ten dumps an hour). How to skip dump creation:
Capistrano 2
In your Capistrano file:
before 'deploy:update_code', 'db:dump' unless fetch(:skip_dump, false)
The second parameter of fetch
sets a default value if skip_dump
is not defined.
In your terminal:
cap staging deploy -S skip_dump=true
The -S
must be a capital letter t...
Merging two arbitrary ActiveRecord scopes
(Rails has a method ActiveRecord::Relation#merge
that can merge ActiveRecord scopes. However, its behavior has never been clear, and in Rails 7 it still discards conditions on the same column by the last condition. We discourage using #merge
!)
The best way to merge ActiveRecord scopes is using a subquery:
scope_a.where(id: scope_b)
It is a little less concise than #merge
, but unambiguous.
Example
Assume a model where a deal has many documents:
class Deal < ApplicationRecord
has_many :...