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
Disable Thumbs.db on Windows 7
Every time you open a directory containing images, Windows creates those pesky Thumbs.db
files for a minor speed-up and lots of cluttering your zip files etc.
You do want to disable them. Here is how on Windows 7:
- Start → Run (or press Meta+R)
- gpedit.msc
- User Configuration → Administrative Templates → Windows Components → Windows Explorer
- Locate "Turn off the caching of thumbnails in hidden thumbs.db files" (should be one of the top list entries)
- Set it to "Enabled". Yes, seriously -- you enable the disabling of thumbs.d...
Check gem dependencies before installation
With gem dependency
it is possible to check the dependencies for your gem before you install it.
Here is an example output for Nokogiri:
Gem nokogiri-1.4.4
hoe (>= 2.6.2, development)
minitest (>= 1.6.0, development)
racc (>= 0, development)
rake-compiler (>= 0, development)
rexical (>= 0, development)
rubyforge (>= 2.0.4, development)
Use look-behind assertions in regular expressions with Ruby 1.8
Regular expressions can have something called "zero-width look-behind assertions". This means that you want a pattern to be preceded by another pattern, but not include the preceding pattern in your match or search cursor. E.g. (?<=x)y
matches y
in xyz
but not in syz
. There are also negative look-behind assertions, e.g. (?<!x)y
matches y
in syz
but not in xyz
.
Unfortunately look-behind assertions are only available in Ruby 1.9. With Ruby 1.8 you need to use an alternative regular expression library called [Oniguruma](http://...
Disable text selection on iOS and Android devices
When you double-tap a string of text on an iPhone or iPad a complicated context menu for copying and pasting will appear. This can confuse unexperienced users.
Use the Javascript hack below to disable text selection on mobile devices:
// Deactivating distracting Text Selection:
// from: http://stackoverflow.com/questions/1794220/how-to-disable-mobilesafari-auto-selection
$.fn.extend({
disableSelection : function() {
this.each(function() {
this.onselectstart = function() {
return false;
...
Get syntax highlighting for puppet files (.pp) in vi
First option is to install it with your package manager:
apt-get install vim-puppet
vim-addons install puppet
If you don't want to install the dependencies download this puppet_syntax.zip and move the content into ~/.vim/
.
Installing Rails on a fresh system
- Install Ruby from the Ubuntu repository:
sudo apt-get install ruby ruby-dev
\
ruby
is the meta package. If you want to explicitly install 1.8 or 1.9, installruby1.8
orruby1.9
instead (the same applies forruby-dev
). - Do not install RubyGems from the repository but install the version from the webpage instead.
- Get Bundler:
sudo gem install bundler
Rails and other gems for a project should now be installed via bundle install
from the...
CPU limit
cpulimit is a simple program which attempts to limit the cpu usage of a process (expressed in percentage, not in cpu time). This is useful to control batch jobs, when you don't want them to eat too much cpu. It does not act on the nice value or other scheduling priority stuff, but on the real cpu usage. Also, it is able to adapt itself to the overall system load, dynamically and quickly.
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.
Fix slow specs using SOLR
I've recently encountered a weird problem with specs making lots of SOLR queries using the acts_as_solr
plugin: After a certain number of specs, exactly one spec suddenly took over 30 seconds to finish.
It turns out that for some reason, the SOLR server seemed not to close its HTTP connections properly. After the maximum number of connections was reached, the next spec needed to wait for an old connection to time out.
I'm not exactly sure why this happened, why it only seems to be happening in specs and which part of the code is actually...
Getting non-Aero toolbars for Thunderbird 5 on Windows 7
Thunderbird 5 brings a custom chrome on Windows Vista/7 that uses translucent Aero decorations on toolbars and menubars. Here is how to restore solid backgrounds if you don't like it.
Put the following into chrome\userChrome.css
in your Thunderbird profile directory:
@namespace url("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul");
window {
background-color: -moz-dialog !important;
}
(Re-)start Thunderbird afterwards.
If you need more info on where the userChrome.css
is suppose...
Traverse large XML files with Nokogiri
If you need to parse a large XML file (> 20 MB or so), you should parse it in chunks, otherwise it will need lots of memory.
Nokogiri offers a reader that lets you parse your XML one node at a time.
Given an XML library.xml
with this content
<library>
<book>
<title>...</title>
<author>...</author>
</book>
<book>
...
</book>
...
</library>
you can for example loop over all books with
def each_book(filename, &block)
File.open(filename) do |file|
...
The challenging setup of an offshore project
After managing a few agile projects from India and learning the tricks of the trade, I have been wondering why life is much easier when you are working closely with the client as compared to working offshore. What worried me more was that I had to learn and use a lot more of project management techniques (making trade offs , managing risks etc..) from offshore, but what mattered while at a local client was building relationships and managing client expectations.
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'...
console-for opens a Rails console remotely on a Capistrano deployment target
We're adding a script console-for
to open a remote Rails console with one command. Also have a look at shell-for
, which this script is relying on.
Run it from any project directory like this, passing a Capistrano multistage deployment target:
console-for staging
This script is part of our geordi gem on github.
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...
Install the SQLite 3 gem for Ruby under Ubuntu
sudo apt-get install sqlite3 libsqlite3-dev
sudo gem install sqlite3-ruby
How to fix zero-byte downloads with Rails 3 and Apache / Passenger
You probably need to activate X-Sendfile.
Test that a string of text is (not) linked in Webrat or Capybara
The step definition below allows you to write:
Then I should see a link labeled "Foo"
But I should not see a link labeled "Bar"
Webrat
Then /^I should( not)? see a link labeled "([^"]*)"$/ do |negate, label|
expectation = negate ? :should_not : :should
response.send(expectation, have_selector("a", :content => label))
end
Capybara
Then /^I should( not)? see a link labeled "([^"]*)"$/ do |negate, label|
expectation = negate ? :should_not : :should
page.send(expectat...
Using Dropbox on Ubuntu
If you are exchanging files with a client via Dropbox you do not need to access the Web page every time you want to fetch files. Instead, you can fully integrate your Dropbox account(s) into nautilus (Gnome's file manager) with automatic synchronization.
- Get the
.deb
file for your system architecture (32 or 64 bit) from the Linux download page. - Install the downloaded package using either the Gnome integration (double-click it) or the shell, e.g.: `dpkg -i naut...
Build vs. Buy
A common question in IT departments is whether to provide a capability by building custom software or by buying a package. If the business process you are supporting is part of your competitive advantage you should build custom software, if not you should buy a package and adjust your business process to fit the way the package works.
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 ...
Force SSH client to use password authentication instead of public key
To test if you can connect to a host using password authentication and explicitly deny public key authentication:
ssh -o PreferredAuthentications=password -o PubkeyAuthentication=no user@host
This also works for Secure Copy:
scp -o PreferredAuthentications=password -o PubkeyAuthentication=no local.file user@host:/path/to/remote.file
Run Selenium tests in Chrome instead of Firefox
Here is how to switch your Selenium to Chrome:
- Make sure you've got a recent version of chromedriver in your
$PATH
See also geordi chromedriver_update which is automatically executed before every usage of geordi cucumber
.
- Register Driver:
Create a file features/support/capybara.rb
with the following content for recent version of Capybara:
Capybara.register_driver :selenium do |app|
Capyb...