The problem I’m trying to solve in this article is comparison of two
audio files. We’ll figure out how to verify that they sound similar.
I was developing an application that has a deal with audio processing and
I had to write a test to verify outcome audio file matches a one
from fixtures. Well, I’ve decided to compare audio binaries like these:
But soon my colleagues let me know I had broken the build. It turned out
that outcome.mp3generated on their Mac books didn’t match fixture.mp3
generated on my linux laptop, despite the fact that both sounded
absolutely the same. Probably we had different codecs.
So I had to come up with a better idea.
apt-cache search ^fonts- - find all packages which starts with fonts-;
sed 's/^\(fonts-[^ ]*\).*$/\1/' - filter output to get only package names;
xargs apt-get install - pass package names to apt-get install to install them.
Now you have more than 1500 fonts, but it’s hard to pick one that you need, because
it’s hard to look through all of them. For our luck there exist specials to preview
fonts, and one of is called fontmatrix. Lets install it:
Few days ago I was writing a ruby wrapper for SoX
command line tool. To reduce disk IO I wanted to use process substitution.
It’s a cool shell feature which allows to use command output as an input file for another command.
It’s pretty useful if the second command doesn’t work with standard input or you need
to pass more than 1 input.
Let me show the classic example(works in bash and zsh):
cat <(echo'Saluton!') <(echo'Kiel vi fartas?')# => Saluton! Kiel vi fartas?
So statement <(echo 'Saluton!') is treated like a file which contains line Saluton!.
Underhood bash(zsh) creates a named pipeline where output of echo 'Saluton!' is written.
Then the named pipeline is passed to cat command.
You can see it:
echo <(echo'Saluton!')# => /dev/fd/63
So I wanted to use it in ruby:
cmd="cat <(echo 'Saluton!') <(echo 'Kiel vi fartas?')"system(cmd)
But unfortunately it doesn’t work:
The problem is that ruby’s system method and back quotes usesh
not your current shell (which in my case is bash).
system"echo $0"# => sh
In shells $0points to the current script or to interpreter if you’re running it interactively.
Fortunately there is a way to create a workaround to run bash:
Sometimes ActiveRecord is not enough to meet complicated validation needs.
At TMXCredit we’ve created Themis -
ActiveRecord extension which helps to organize validations in a better way and adds
some flexibility. Here I’m gonna describe some problems which Themis solves after that
I’ll take a brief look at possible alternative solutions.
Themis allows you to extract duplicated validations into module for reuse.
Usually rails applications are small enough so you don’t need it. But sometimes
The next example is pretty flat(in real life you probably would use STI or composition to
represent Doctor and Patient models) but it illustrates where Themis could be useful.
You see that both models have the same validation for first_name, last_name and email.
Themis allows you to fix the duplication problem by extracting common validations into
# Module with common validations.modulePersonValidationextendThemis::Validationvalidates:first_name,:last_name,:email,:presence=>trueendclassDoctor<ActiveRecord::Base# import validation of first_name, last_name, emailincludePersonValidationvalidates:diploma,:presence=>trueendclassPatient<ActiveRecord::BaseincludePersonValidationvalidates:age,:presence=>trueend
Как вы знаете, я начал изучать Эсперанто, некоторым даже успел “съесть” мозг, но всё же большинство по-прежнему задают вопросы почему и для чего я это делаю. Из этого можно прийти к выводу, что либо я безумен, либо я понимаю что-то, что другие не могут понять.
Поэтому я решил написать небольшую статью и постараться объясниться.
After migrating to Debian Wheezy (current test Debian repository) I faced a problem
with installing a local USB printer: on attempt to add new USB printer
(HP LaserJet M1005) I got an error message: “Failed to add new printer in Debian Wheezy”
(“Не удалось добавить новый принтер” if you have Russian localization).
After googling for I a while I found a good workaround for it. All you need is
to use pk-helper package from Sid (unstable Debian version), since it seems to
be buggy in Wheezy.
So add Sid repository to your /etc/apt/source.list:
deb http://ftp.ua.debian.org/debian/ sid main non-free contrib
And reinstall cups-pk-helper package using Sid repository:
aptitude reinstall cups-pk-helper --target sid
That’s all. Now try to connect your USB printer.
Btw, there is the bug report.
Trying to move a rails application from ruby 1.8.7 to 1.9.3 I ran into coercion
issue of Rational class.
require'bigdecimal'require'rational'# You can multiply Rational against BigDecimalRational(1)*BigDecimal('1')# => <BigDecimal:a566d0,'0.1E1',9(36)># But you can't do the same when you change orderBigDecimal('1')*Rational(1)# => TypeError: Rational can't be coerced into BigDecimal
On other hand in Ruby 1.8.7:
require'bigdecimal'require'rational'# BigDecimal * Rational works OKBigDecimal('1')*Rational(1)# => 1.0 (Float)# But Rational * BigDecimal doesn'tRational(1)*BigDecimal('1')# => TypeError: Rational can't be coerced into BigDecimal
It’s looks weird. So I can only say for sure that Rational -> BigDecimal
coercion is not implemented in Ruby.
I’ve tried to fix it with simple monkey patch:
# Works only for Ruby1.9.3classRationaldefcoerce(value)casevaluewhenBigDecimalreturnself,valueelsesuperendendend