Did you return false
in a before_validation
callback?
Sometimes the Rails helper #distance_of_time_in_words
is using too much magic.
When you need a time difference in a specific unit, use this method:
^
def distance_of_time_in(unit, from, to)
diff = to - from
if 1.respond_to? unit
distance = diff / 1.send(unit)
distance.abs.round
else
raise ArgumentError, "#{unit.inspect} is not supported as unit"
end
end
distance_of_time_in(:days, Time.now, 1.year.ago)
=> 365
Remove the .abs
if you want the mathematical *differ...
Pdfposter is a Python script that allows to convert large PDFs into a PDF with multiple pages that can be printed and turned into one big poster.
In Ubuntu, you can install it with
sudo apt-get install pdfposter
Scaling to the desired size is a bit cumbersome. If you want to split large.pdf
, I suggest you run
pdfposter -vns 0.5 large.pdf larger.poster.pdf
which will tell you into how many pages the file would be split. Then simply tweak the -s
value till you get the desired number of pages, and remove the -n
to generate the r...
When browsing a repository, pressing "t" allows you to quickly search for file names. Very awesome!
Go here to try it out.
I recently browsed through the ActiveSupport code and found some nice stuff I did not know about:
ActiveSupport::Callbacks
: ActiveRecord-like callbacks, if you need callbacks in non ActiveRecord objects
ActiveSupport::MessageEncryptor
: encrypt and decrypt ruby objects
[ActiveSupport::MessageVerifier
](https://github.com/rails/rails/blob/master...
Consider this HTML:
<div style="line-height: 42px">
<input type="checkbox" />
</div>
Even though the surrounding container defines a line-height
, which vertically centers its inline elements, the check box will be top aligned if it is the only element inside the container.
It will be aligned correctly if the HTML looks like this:
<div style="line-height: 42px">
<input type="checkbox" /> foo
</div>
So the ac...
When the Ruby parser module of Ruby-GetText comes across a file in one of its search directories (e.g. lib/scripts/
) and finds out that you are defining ActiveRecord classes inside it, it evaluates the whole file. Here is how to avoid that.
Let's say you have the following script which is only run once, manually, via script/runner
:
# lib/scripts/doomsday.rb
class User < ActiveRecord::Base; end
User.destroy_all
In that case we ...
Do you wonder which databases are actually taking up how much space but only have one huge ibdata1
in your /var/lib/mysql
and the directories inside your mysql data directory don't represent the actual database sizes? This is for you!
Run from a mysql root console:
SELECT table_schema AS "Database name", SUM(data_length + index_length) / 1024 / 1024 AS "Size (MB)" FROM information_schema.TABLES GROUP BY table_schema;
This will get you a result like the following:
+----------------------+--------------+
| Database name ...
Grep prints one line per match. To return the number if matches, use the -c
switch:
grep -c "something" filename
However, if a word appears more than once in a line, it is only counted once.
To count every match, you can use sed
to force line breaks on multiple matches:
sed 's/something/something\n/g' filename | grep -c "something"
If you want to use the (badly implemented!) solarized color scheme in your Rubymine IDE:
Clone the IntelliJ IDEA port:
git clone https://github.com/jkaving/intellij-colors-solarized.git
Import the settings in Rubymine by chosing the above directory File -> Import Settings
Change the color scheme in the settings (Ctrl-Alt-S) in Editor -> Colors & Fonts
Note that selecting a color scheme will also reset your previous editor font choice. You might want to change the font to [Envy Code R](http://damieng.com/blog/2008/05/2...
This article from the FreeBSD Handbook suggests that editing /etc/rc.conf
enables DHCP. Unfortunately, some times this seems not sufficient.
Try a reboot, or start the DHCP client manually with the command
dhclient <network adapter>
You can find a list of network adapters by running ifconfig
. Examples are em0
or lo0
.
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.
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.
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 [...
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:
sudo mdadm --create -f /dev/md0 --chunk=256 --level 10 --raid-devices 4 /dev/sdf /dev/sdg /dev/sdh /dev/sdi
/dev/md0
using mkfs*-toolsMake sure the last line in `/etc/mdadm/md...
Solarized is a sixteen color palette (eight monotones, eight accent colors) designed for use with terminal and gui applications. It has several unique properties. I designed this colorscheme with both precise CIELAB lightness relationships and a refined set of hues based on fixed color wheel relationships. It has been tested extensively in real world use on color calibrated displays (as well as uncalibrated/intentionally miscalibrated displays) and in a variety of lighting conditions.
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
.
If you use Nginx with SSL and get an intermediate certificate with your certificate you have to do this:
cat /path/to/intermediate/certificate >> /path/to/certificate
Whenever you deploy using Capistrano, a new folder is created within the releases directory on the remote server containing the application code.
By default Capistrano 3 keeps the last 5 releases in case you need to rollback to an older release. You can overwrite this setting by using
set :keep_releases, 3
Attached is a working config to deploy an application with Capistrano that needs to monitor Resque workers with God.
God will run as the deployment user, no need to register it as a system service.
Put this into your config/deploy.rb
:
namespace :god do
def god_is_running
!capture("#{god_command} status >/dev/null 2>/dev/null || echo 'not running'").start_with?('not running')
end
def god_command
...
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:
q
to enter macro mode.q
again to stop recording.@
and its assigned letter key.Cheats:
@
key. Example: ...Chosen is a JavaScript plugin that makes long, unwieldy select boxes much more user-friendly. It is currently available in both jQuery and Prototype flavors.
To avoid sending e-mails containing sensitive data unencrypted I strongly suggest you enable a confirmation dialog.
Enigmail can show if the e-mail being sent will be encrypted or not -- and if, which keys will be used. This applies to both clicking the "Send" button or pressing Ctrl+Enter. Thus, you may disable the confirmation for the keyboard shortcut as you get a message box anyways which will avoid sending e-mails by accident.
Head over to the Enigmail preferences from the "OpenPGP" menu and tick the corresponding che...
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...
If you get the error "413 Request Entity Too Large" from Nginx client_max_body_size
is too low (default is client_max_body_size=1m
).
This can happen for example during file upload.