HMBR


Bash ‘must know’ tips
July 13, 2010, 1:08 am
Filed under: nerd, open source

Usually I read a lot of bash tips, codes, snippets, but some tips are hard to find, let see 2 tips:

Read Line

The ideia is, read each line of a file using bash, some people use terrible ways to do this job.

Bash has a simple way, $(< filename)

echo $(< file.txt)

Apparently the command did’n work, but the fact’s, the command worked, but printed line by line without ‘\n’.

This for show how to work with each line.

for i in $(<file); do echo $i; done

Rename only the extension

This is simple, some tasks need a in file and a out file, the two files can be different, if we need a ‘for’ we need create a good number of files.

Instead of create something like foo.txt and foo.txt.xml, you can create one foo.xml.

Let’s use ${//}  to improve your  work.


$variable = name.foo
echo ${variable/foo/bar}

Inside a for, is awesome:

for i in */*.xml; do xml2xsd $i ${i/xml/xsd}; done

Thanks

Advertisements


Como utilizar o Mascaramento de pacotes para descobrir as causas de um downgrade.
August 25, 2008, 12:33 am
Filed under: gentoo, gentoobr, nerd, open source

Uma das coisas mais comuns no uso do gentoo, principalmente quando mistura pacotes estáveis, testings e unstables (como eu costumo fazer), é o downgrade de algum pacote para alguma versão anterior sem uma razão aparente, como o downgrade de uma versão estável para uma antiga versão.

Isso ocorreu comigo quando fui realizar um emerge -NDuav word:

hellboy ~ # emerge -NDuav world


These are the packages that would be merged, in order:


Calculating world dependencies... done!
[ebuild     UD] dev-util/bzr-1.1 [1.5] USE="bash-completion -curl -emacs -sftp -test" 3,346 kB
[ebuild     U ] app-text/poppler-0.8.6 [0.8.5] USE="jpeg zlib -cjk" 1,435 kB
[ebuild     U ] app-text/poppler-bindings-0.8.6 [0.8.5] USE="cairo gtk -qt3 -qt4 -test" 0 kB


Total: 3 packages (2 upgrades, 1 downgrade), Size of downloads: 4,781 kB


Would you like to merge these packages? [Yes/No]

Vejam o caso do bazaar (dev-util/bzr), mas acontece que a versão 1.5 é uma versão estável como aponta o eix:

hellboy ~ # eix dev-util/bzr
[I] dev-util/bzr
Available versions:  0.17 1.1 ~1.3 ~1.4 1.5 [M]~1.6_rc5 {bash-completion curl emacs sftp test}
Installed versions:  1.5(07:43:31 PM 08/23/2008)(bash-completion -curl -emacs -sftp -test)
Homepage:            http://bazaar-vcs.org/
Description:         Bazaar is a next generation distributed version control system.

A razão deste comportamento é sempre por causa de algum pacote já instalado ou que vai ser instalado, eu acho que a maneira abaixo a mais simples para descobrir qual o pacote esta forçando o downgrade.

Primeiro eu mascaro o todas as versões abaixo da versão já instalada do programa que esta sendo forçado o downgrade, no caso, todas as versões do bazaar abaixo do 1.5.

sudo echo '<=dev-util/bzr-1.4' >> /etc/portage/package.mask

Feito isso, refaço o comando que originou o pedido de downgrade e vejo o resultado:

hellboy ~ # emerge -NDuav world


These are the packages that would be merged, in order:


Calculating world dependencies /
!!! All ebuilds that could satisfy "=dev-util/bzr-1.1*" have been masked.
!!! One of the following masked packages is required to complete your request:
- dev-util/bzr-1.1 (masked by: package.mask)


For more information, see MASKED PACKAGES section in the emerge man page or
refer to the Gentoo Handbook.
(dependency required by "dev-util/bzrtools-1.1.0" [installed])


!!! Problem resolving dependencies for dev-util/bzrtools
!!! Depgraph creation failed.

Dai eu observo que o responsável pelo downgrade é o pacote dev-util/bzrtools, que consta com todas as versões consideradas como instáveis:

hellboy ~ # eix bzrtools
[I] dev-util/bzrtools
Available versions:  ~0.17.1 (~)1.1.0 ~1.3.0 ~1.4.0 ~1.5.0
Installed versions:  1.1.0(02:34:38 AM 02/06/2008)
Homepage:            http://bazaar.canonical.com/BzrTools
Description:         bzrtools is a useful collection of utilities for bzr.

Como é um caso de pacotes instáveis, uma maneira seria apagar o pacote instável ou utilizar a keyword, como eu estou querendo aprender mais do bazaar, prefiro arriscar utilizar o pacote instável.

sudo echo '=dev-util/bzrtools-1.5.0 ~*' >> /etc/portage/package.keywords

Com isso elimino a fonte do downgrade e refaço o meu comando sem medo de downgrades :-D.

hellboy ~ # emerge -NDuav world


These are the packages that would be merged, in order:


Calculating world dependencies... done!
[ebuild     U ] dev-util/bzrtools-1.5.0 [1.1.0] 82 kB
[ebuild     U ] app-text/poppler-0.8.6 [0.8.5] USE="jpeg zlib -cjk" 1,435 kB
[ebuild     U ] app-text/poppler-bindings-0.8.6 [0.8.5] USE="cairo gtk -qt3 -qt4 -test" 0 kB


Total: 3 packages (3 upgrades), Size of downloads: 1,517 kB


Would you like to merge these packages? [Yes/No]

😀



What Color Is Your Mind?
April 24, 2008, 1:59 am
Filed under: nerd

Your Mind is Green


Of all the mind types, yours has the most balance.

You are able to see all sides to most problems and are a good problem solver.

You need time to work out your thoughts, but you don’t get stuck in bad thinking patterns.

You tend to spend a lot of time thinking about the future, philosophy, and relationships (both personal and intellectual).

What Color Is Your Mind?


batch scanning
April 21, 2008, 4:03 pm
Filed under: nerd, open source

As vezes é necessário copiar uma quantidade bizarra de arquivos, uma maneira simples de colocar em batch esta tarefa.

 1 #!/bin/bash
 2
 3 device="hpaio:/usb/Photosmart_C3100_series?serial=BR73NGQ13X04KV";
 4
 5 while true;
 6
 7     do if [[ -a stop_file ]];
 8         then break ;
 9     fi;
10
11     echo "scanning" ;
12     name=`date +%s` ;
13     scanimage -d $device -p >$name.pnm;
14
15     convert $name.pnm $name.jpg;
16     rm $name.pnm;
17
18     echo "sleeping" ;
19     sleep 10s;
20
21     do if [[ -a stop_file ]];
22         then break ;
23     fi;
24
25 done


I’m just too White and Nerdy
November 22, 2006, 12:27 pm
Filed under: nerd, youtube



Firefox Party
October 18, 2006, 2:17 pm
Filed under: firefox, nerd, open source

Every time, when a big change is coming, when people builds new concepts together, work together, no matter who you is, no matter who are you, the only thing that matters is “we did this together”.

When things like that happens, we need celebrate.

baby

Now is a time to celebrate, Firefox 2.0 is almost done, concepts are chancing, we need celebrate.

Mozilla foundation are calling all firefox users from all over the world to celebrate, prepare your party, call your friends and have fun.

Link: http://www.firefoxparty.com



The Lord of the XMLs
October 10, 2006, 5:45 pm
Filed under: nerd

One DTD to rule them all, One XPATH to find them,

One XSLT to bring them all and in the server transform them.