Posts Tagged ‘console’

It’s the little things I like about Linux

Tuesday, January 8th, 2008

Today I wrote some handy syncronization-scripts with the help of my freebsd-loving co-worker Marius. Till today I managed the syncronization of my local database with our production database with the help of phpMyAdmin.
An export of the 13mb sql file at the production server and an import at my machine took me at least five minutes (~2mb gzipped). Now take a look at this:

[hans@zommuntu:~]$ time ssh user@production_server "mysqldump --add-drop-table database_to_process -uUSER -pPASSWORD | gzip" | gunzip | mysql -uLOCALUSER -pLOCALPASSWORD database_name
real    0m4.389s
user    0m0.592s
sys     0m0.052s

Under five seconds! woot!!
Some words to explain this: First, you establish a ssh connection to the production_server. The gzipped dumped sql of the beloved database_to_process is transferred to your machine. Here it is gunzipped and written to your local database server into the database_name. The quotes are necessary as brackets to let the script know that the gzip command belongs to the ssh command.

Translate directly at your console!

Monday, January 7th, 2008

Ever wanted to be able to translate directly at your cosole?

[hans@zommuntu:~/rails]$ de2en häuser
Homes
[hans@zommuntu:~/rails]$ en2de houses
Häuser

Save this ruby-script as en2de in your ~/bin:

#! /usr/bin/ruby

#
# Copyright (c) 2008 gauda.de
# All rights reserved.
# This program is free software; you can redistribute it and/or
# modify it under the same terms as Ruby itself.
#

require 'net/http'
require 'iconv'
require 'uri'

arg = URI.escape(Iconv.new('ISO-8859-15', 'UTF-8').iconv(ARGV[0]))
str = Net::HTTP.new('www.google.com', 80).get("/translate_t?text=" + arg + "&langpair=de|en").body.match(/id\=result_box\ dir\="ltr">(\S*)<\/div>/)
if str
  puts Iconv.new('UTF-8', 'ISO-8859-15').iconv(str[1])
else
  puts "error.."
end

Of course you can change the languages! Just edit the langpair=de|en at your will. Be sure to have ruby installed!