RubyMine crashes Ubuntu 11.04 window decorator on exit
My RubyMine (and it seems like many other Java GUI applications) crashes the Compiz window decorator almost every time on exit. This also seems to happen for the Unity decorator.
Update: The commited fix from below seems to have made it into the stable Ubuntu repository.
Easy mode
You can restore window decorations by executing this command:
gtk-window-decorator --replace &
This is only a temporary fix.
Hard mode
Also, there is a committed fix that is n...
How to use helper methods inside a model
Simple
If you want to use a helper_method my_helper_method
inside a model, you can write
ApplicationController.helpers.my_helper_method
When using multiple helpers
delegate :helpers, to: ApplicationController
helpers.my_helper_method
helpers.my_other_helper-method
More flexible
If you need a bit more flexibility, for example if you also need to override some methods, you can do this:
class HelperProxy < ActionView::Base
include ApplicationController.master_helper_modu...
Unsafe string methods in Rails
When you encouter an unsafe string that you actually made html_safe
before, perhaps you called one of the following methods on it:
"capitalize", "chomp", "chop", "delete", "downcase", "gsub", "lstrip", "next", "reverse", "rstrip", "slice", "squeeze", "strip", "sub", "succ", "swapcase", "tr", "tr_s", "upcase"
All these methods are possibly unsafe, so they will return an unsafe String
even if called on a SafeBuffer
. If used for in-place replacements (e.g. sub!
instead of sub
), a TypeError
is raised.
This is to prevent tric...
markbates/coffeebeans
When CoffeeScript was added to Rails 3.1 they forgot one very important part, the ability to use it when responding to JavaScript (JS) requests!
In Rails 3.1 it’s incredibly easy to build your application’s JavaScript using CoffeeScript, however if you fire off an AJAX request to your application you can only write your response using regular JavaScript and not CoffeeScript, at least until CoffeeBeans came along.
How to use Git on Windows with PuTTY
-
Get "PuTTY Link" and "Pageant" (an SSH key agent) from the PuTTY download page.
-
Run
pageant.exe
, find its icon inside your system tray and add your SSH key. -
Open up a
cmd
and put the full path to PuTTY'splink.exe
into theGIT_SSH
environment variable, e.g.:set GIT_SSH=D:\PuTTY\plink.exe
You can then use Git like you would on any sane operating system. Just go ahead and git clone
, git pull
, etc.
Also, you may want to add the environment vari...
Using RSpec's late resolving of "let" variables for cleaner specs
Consider the following:
describe '#something' do
context 'with lots of required arguments' do
it 'should work' do
subject.something(:foo => 'foo', :bar => 'bar', :baz => 'baz').should == 'Hello world'
end
it 'should work again' do
subject.stub :target => 'universe'
subject.something(:foo => 'foo', :bar => 'bar', :baz => 'baz').should == 'Hello universe'
end
it 'should work yet again' do
subject.stub :target => 'multiverse'
subject.something...
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...
Read your mail in networks that forbid e-mail traffic
If you are connected with a network that forbids e-mail traffic but allows SSH, you can tunnel your e-mail connection through a trusted, intermediary server:
sudo ssh -i /home/local-user/.ssh/local-user.key -L 143:mail-server.tld:143 remote-user@trusted-server.tld
Explanation for the command above:
| sudo
| Secure ports may only be forwarded by root |
| ssh -i /home/local-user/.ssh/local-user.key
| Private half of your SSH key for the trusted server |
| -L 143:mail-server.tld:143
| Forward connections to port 143 on your mail s...
Move a Gnome panel to another monitor in Ubuntu
In older Ubuntu releases you could ALT+drag any panel bar to another position and/or monitor. In Ubuntu 11.04 Natty you need to perform the steps from the attached article instead:
- Right-click on the panel to access the panel properties
- Uncheck "Expand"
- Move the panel by dragging the grip areas that now appear on the panel edges
- Check "Expand" again in the panel properties
Opening Rubymine projects from the command line
To activate the shell command, go to Tools > Create Command-line Launcher
and confirm.
Now you have mine
as bash command. Run this to open a project in RubyMine:
mine path/to/my_project
Booting Rubymine
The mine
script will attach the opened project to a current Rubymine instance. If there is none, it will run Rubymine right there on your command line.
To move Rubymine to the background and suppress log messages you can create your own shell script (vim ~/bin/rubymine
):
#!/bin/sh
( mine "$@" & ) > /dev/null ...
Lessons learned from implementing Highrise's custom fields feature
We recently added custom fields to Highrise which allow you to keep track of extra details beyond standard contact information like phone, email, address, etc. After the launch, we had a “looking back” conversation to see what lessons could be learned from the process.
Better is better: improving productivity through programming languages
All you need to know about the rise and fall of programming languages. Not really related to the worse is better essay linked here earlier.
The Rise of "Worse is Better"
An ancient essay on software design that, after 20 years, should still guide you for every line of code you write.
When Google analytics won't let you add a @googlemail.com account
If Google Analytics claims that a something@googlemail.com
address is not a valid Google account, try adding something@gmail.com
.
This seems to affect Google accounts that were created long ago.
"no such file to load require_relative (MissingSourceFile)" after installing ruby-debug
If you encounter above mentioned failiure message after installing the ruby-debug gem then you have to explicitly require linecache version 0.43 in your Gemfile.
gem 'ruby-debug'
gem 'linecache', '=0.43'
Helpers to render (money) amounts
When rendering a number, you want to pretty up the string coming from #to_s
:
- Render
0.0
as0
- Sometimes require a minimum number of digits after the decimal separator
- Change the decimal separator from
.
to,
in some European countries - Render a dash if the given amount is
nil
The attached helper that does just that. Some usage examples with their resulting strings:
Invocation | Result |
---|---|
amount(0) |
0 |
amount(0.0) |
0 |
amount(0.5) |
0,5 |
amount(1.5, :minimum_precision => 2) |
1,50 |
`amo... |
Why developers should be force-fed state machines
Most web applications contain several examples of state machines, including accounts and subscriptions, invoices, orders, blog posts, and many more. The problem is that you might not necessarily think of them as state machines while designing your application. Therefore, it is good to have some indicators to recognize them early on. The easiest way is to look at your data model.
What’s Up With All These Changes in Rails?
Yesterday, there was a blog post entitled “What the Hell is Happening to Rails” that stayed at the number one spot on Hacker News for quite a while. The post and many (but not most) the comments on the post reflect deep-seated concern about the recent direction of Rails. Others have addressed the core question about change in the framework, but I’d like to address questions about specific changes that came up in the post and comments.
Unpack a .tar.gz archive
You can unpack a .tar.gz
file into the current directory like this:
tar -xzvf archive.tar.gz
The options used are
-x
-
Extract
-z
-
Unzip
-f
-
Process a file input
-v
-
Be verbose, i.e. print each extracted file
Side notes:
- The dash is optional (
tar xzvf ...
works as well). - For
.tar.bz2
archives, usej
instead ofz
(tar xjvf
...`) - In order to create a *.tar.gz archive, use
-c
flag instead of-x
flag. - The order of parameters matters.
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...
Stubbed class methods in RSpec 1 remain stubbed in other examples
I encountered a bug in RSpec 1.x where stubbed class methods ("static methods") would not be unstubbed before the next example, causing it to fail. This behavior can come and go as you edit your specs, since this can change the order in which RSpec evaluates your .rb
files.
I was not able to find a fix for this behavior. Calling #rspec_reset
und #unstub!(:method)
on the class after the example did not help. I know for sure that stubbing static methods has not been a problem in many other projects. I encountered the bug while working o...
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...
15 criteria for evaluating software product ideas
Choosing the right product to develop is crucial. Great execution is also very important. But if you develop a product that no-one wants or no-one is prepared to pay for, then you are going to fail, no matter how well you execute it. You can often tweak a product or its marketing to make it more successful based on market feedback (‘pivot’) . But the less pivoting you have to do, the better. Below I list some of the criteria I think are important for evaluating the potential of new commercial software products.
Example .ssh/config file
Attached you can find an example ~/.ssh/config
file which makes working with SSH more pleasant. It contains several tweaks:
- Default settings
- Defining host aliases in your SSH config
- Don't let your SSH session die
After you download the file to ~/.ssh/config
, edit the file in a text editor to tailor it to your individual needs.