sudo command for Windows
There is no good equivalent for the Unix sudo command in Windows. Below are a few workarounds that are all unsatisfactory to some degree.
Run the command prompt as Administrator
- Right-click on the Command Prompt icon
- Select Run as Administrator
- Do what you need to do
- Quickly close the terminal
Sudo for Windows
If you are using an English Windows, you can use Sudo for Windows. Unfor...
Ubuntu: Open a new terminal window with a keyboard shortcut
To open a terminal quickly navigate to System → Preferences → Keyboard Shortcuts. There, click the "Run a terminal" row (It should be in the "Desktop" section) and press the keyboard shortcut you like.
If you cannot find such an entry you may need to add it yourself -- the command for Ubuntu's default terminal is gnome-terminal
.
Be aware that many programs use shortcuts of their own and you would not want to clash with those (like Ctrl+T
). Something like Meta
+T
is something usually not ta...
Maximum representable value for a Ruby Time object
On 32bit systems, the maximum representable Time is 2038-01-19 03:14:07
in UTC or 2038-01-19 04:14:07
in CET. If you try to instantiate a Time
with any later value, Ruby will raise an ArgumentError
.
If you need to represent later time values, use the DateTime class. This is also what Rails does when it loads a record from the database that has a DATETIME value which Time
cannot represent. Note that there are some [subtle differences](http://stackoverflow.com/quest...
How to change MySQL's data directory
-
Have a backup.
-
Stop MySQL:
sudo service mysql stop
-
Move (or copy) your
mysql
directory. If you want/mnt/mysql
to be the new directory, do it like this:sudo mv /var/lib/mysql /mnt/
-
Open your MySQL configuration (
sudo vim /etc/mysql/my.cnf
) and change thedatadir
value to your new path (e.g./mnt/mysql
) -
Modify your AppArmor configuration:
sudo vim /etc/apparmor.d/usr.sbin.mysqld
Change/copy the lines granting access to
/var/lib/mysql
to your new path. Otherwise MySQL will not ...
HTML5 and Web Video: Questions for the Industry from the Community
What are Google’s plans for turning WebM into a genuinely open standard, one that is based on consensus like the rest of W3C’s HTML5 effort? Would Google fully support such an effort? Even the WebM project’s domain is controlled by Google. Google chose to release WebM under the Creative Commons license which would theoretically allow a standards body to use the specification as a basis for a truly open standard. Would Google agree to adopt the specification and changes that would emerge from an open process in a timely and robust manner? Wha...
Encrypt files using OpenSSL
Using OpenSSL it's very easy to seriously encrypt files.
Use the script below. Input / Output are self explanatory. Put a long passphrase into PASSWORD_FILENAME. It is the key to decrypt to file again. Paste this into a console and copy it to wherever you need it.
touch /tmp/openssl_encryption_password && chmod 0700 /tmp/openssl_encryption_password && apg -n1 -m 60 > /tmp/openssl_encryption_password
Remember to at least delete the input file afterwards. Better use [shred to wipe files on Linux](https://makandracards.com/makandra/1013-s...
Securely remove files on Linux
When you delete a file with rm
it's still possible to recover the file or parts of it. Use shred
to overwrite the content of a file and delete it afterwards.
shred -u $file
Be aware that this is not sufficient for flash memory, like SSDs or USB pen drives. The write will possibly target another memory area than where the file was located previously. Prefer disk encryption whenever possible.
Erasing directories
To erase complete directory structures, using shred
is cumbersome. Use wipe
instead:
wipe -...
Upgrade from Rails 2.3.10 to Rails 2.3.11
See our new comprehensive guide for upgrading every Rails 2 version ever.
Dump your database with dumple
This tool is used on our application servers (and called when deploying) but it also works locally.
Just call dumple development
from your project directory to dump your database.
This script is part of our geordi gem on github.
Validate an XML document against an XSD schema with Ruby and Nokogiri
The code below shows a method #validate
which uses Nokogiri to validate an XML document against an XSD schema. It returns an array of Nokogiri::XML::SyntaxError objects.
require 'rubygems'
gem 'nokogiri'
require 'nokogiri'
def validate(document_path, schema_path, root_element)
schema = Nokogiri::XML::Schema(File.read(schema_path))
document = Nokogiri::XML(File.read(document_path))
schema.validate(document.xpath("//#{root_element}").to_s)
end
v...
Continously run command under bash
Sometimes you want to run a command forever, e.g. to compile a haml to html file on the console. Use this:
$ while(true) do haml index.haml index.html; sleep 1.5; done
Cucumber fails without giving error message
To improve your chances to get proper error messages, you can try
^
- to start cucumber with the
-b
option, so it shows a full backtrace - to start cucumber with the
-f pretty
option to get a more verbose formatter - to start cucumber with the
-d
option to show debug information
Linux: rename or change extension of multiple files
When you need to bulk rename files you can not call "mv *.foo *.bar
" to change the extension of all .foo
files to bar
(because bash resolves wildcards and replaces them with the list of matched files).
This works on linuxes who use the Perl version of the rename
command (like Ubuntu):
rename 's/\.foo$/\.bar/' *
You can also use this to rename other parts of the file, e.g. from flag_en.png
, flag_de.png
etc. to just en.png
or de.png
:
rename 's/^flag_//' *
Note that we used $
and ^
to explicitly look at the ...
Deploy and migrate with a single Capistrano command
Note that this sounds good but is not good at all when hooking tasks on cap deploy
(see this article). Make sure to hook your calls properly when using this.
To deploy an application and run all pending migrations before restarting it, you can use the following standard Capistrano task:
cap deploy:migrations
Little is known what happens when the deployment goes through, but a migration or a rake task aft...
Show the description of a Capistrano task
In order to bring up a textual description of a Capistrano task you can say
cap -e taskname
... where taskname
is the name of the task you're not sure about.
Auto-hide player controls in the default Flash video player component
If you find yourself working in the Adobe Flash IDE you're already doing it wrong, but maybe the hour is late and your standards for success are slipping. Anyway here is how to hide the controls in the default Flash video player component:
- Select the player frame on the stage.
- Open the component inspector by selecting
Window -> Component Inspector
or clicking a funny unlabeled icon in the player properties. - Set the
skinAutoHide
property totrue
.
Test that a select field contains an option with Cucumber
This note describes a Cucumber step definition that lets you say:
Then "Mow lawn" should be an option for "Activity"
But "Reply support mail" should not be an option for "Activity"
Note that this step checks whether an option is available, not that it is selected. There is a separate step to test that an option is selected.
Capybara (0.4.1 or higher)
Then /^"([^"]*)" should( not)? be an option for "([^"]*)"(?: within "([^\...
Fix errors when rendering PDF output
If you run specs or your application and get an error like:
ActionController::MissingFile in 'ProductsController#show, should render PDF'
Cannot read file /some/file.pdf
You may be missing the HTMLDOC binary on your system. Install it like this on Debian/Ubuntu:
sudo apt-get install htmldoc
Show the name and version of your Linux distribution
To list the name and version of your Linux distribution, type the following:
cat /etc/*-release
hyphenator
Javascript that implements client-side hyphenation of HTML-Documents.
remove_index fails silently for non-existing indexes in Rails 2 migrations
When you try to remove a non-existing index using remove_index
, the migration will incorrectly pass without an error. The schema will not be changed, but the migration will be considered migrated.
Since this might be fixed in the future, you cannot mend your database by adding another migration on top of the faulty one. You should manually alter the database schema to the previous migration on all machines that migrated the faulty migration (inform your fellow developers), then delete the faulty migration from the repository.
The Case Against Queues
Some people, when confronted with a problem, think "I know, I'll use a queue." Now they have an unbounded number of problems.
Networked message queues like ActiveMQ, RabbitMQ, ZeroMQ, and a host of other Java inspired software tumors are crutches of systems design. I love asynchronous stuff as much as the next guy, but think of a queue like Java: it encourages large swaths of mediocre programmers to overengineer shit, and it keeps systems administrators in business by giving them something to respond to at 4AM.
Here is some of th...
Using Firebug Lite to inspect HTML in Internet Explorer and other browsers
You know Firebug as a Firefox extension but there is also a "Lite" version which runs purely off JavaScript.
Though all major browsers offer inspection tools you may like the Firebug style. Also, for me this is a lot better than the IE8 developer tools -- and it works in older versions of IE, too.
Get the bookmarklet over at http://getfirebug.com/firebuglite#Stable. It usually loads the JavaScript code from a remote server but you can also download it to have it run locally. If adding the bookmarklet does not work in IE, add a new book...
babushka: test-driven sysadmin
The idea is this: you take a job that you'd rather not do manually, and describe it to babushka using its DSL. The way it works, babushka not only knows how to accomplish each part of the job, it also knows how to check if each part is already done. You're teaching babushka to achieve an end goal with whatever runtime conditions you throw at it, not just to perform the task that would get you there from the very start.