Category
shell
-
05.15.12ASCII codes in VimToday, a work mate asked if anyone had an ASCII code table at hand. He was editing a file in Vim and wanted to know the ASCII code for a certain character. Here is the answer: While having the cursor on the character, type: <ESC>:ascii<ENTER> Enjoy!
-
03.06.12Colored diffAs a programmer I am used to dealing with diff files. If you do not know what a diff file is, here you can find a nice description. They are simply text files so they can be viewed with less, more, cat and other common utilities. The main problem is that those utilities do not recognize these files' special syntax. cdiff (/usr/ports/textproc/cdiff) is a small utility that shows diff files in a colored fashion. It can be used this way: $ cdiff file.diff Of course, Vim can be useful here too ;) svn diff | vim -R - Enjoy!
-
01.09.12Greping from inside VimHi there, First things first: Happy New Year! :) One task I usually perform when I am writing code is grepping the code for a certain string. In order to do that, I used to exit Vim (either with :q or suspending the process), grep the files and then go back to my Vim session. This approximation has one main drawback: I usually don't remember all the matches reported by grep. Vim provides a mechanism for invoking grep from a Vim session. The command is: :grep string files This way, one can invoke his local grep command and the results will be integrated into the ...
-
11.12.11Unicode sorting in perlJust Normalize. Assume file.txt is a list of unicode words, then cat file.txt | perl -e 'use Unicode::Normalize; my @w ;\ while () {chomp; push @w, $_;} ; @w = sort {NFD($a) cmp NFD($b) } @w ;\ print(join("\n", @w))' will output the sorted list (well, sorted according to the NFD normalization, which for Spanish is enough).
-
10.15.11Creating shell archivesshar(1) is a FreeBSD base system utility for creating shell archives that is, a kind of self-extracting archive of a hierarchy of files and directories. The archive will recreate the file hierarchy specified at creation time. It is fast and the result is easy to handle as the shell archive is a text file (good to email a file hierarchy). To create a shell archive: $ shar `find my_directory` > my_hierarchy.shar To recreate the hierarchy: $ sh my_hierarchy.shar That is, shar is a simpler version of ar and tar. Enjoy!
-
09.22.11How to know if a CPU is 32 or 64-bitNowadays almost all the computers have a 64-bit CPU, but sometimes we are logged in on a remote server and do not know what kind of CPU it has and we need to know it to install a package or... out of mere curiosity. In those cases we can run the following command: $ grep --color lm /proc/cpuinfo flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss syscall nx rdtscp lm constant_tsc up ida nonstop_tsc arat pni ssse3 cx16 sse4_1 sse4_2 popcnt lahf_lm If the lm flag ...
-
09.13.11Audio settings on FreeBSDmixer(8) is a FreeBSD base system utility for setting and displaying sound card mixer levels. It resembles the Linux's command line utility alsamixer. Invoked with no parameters it shows the current values of the mixer devices: $ mixer Mixer vol is currently set to 85:85 Mixer pcm is currently set to 75:75 Mixer speaker is currently set to 75:75 Mixer mic is currently set to 0:0 Mixer mix is currently set to 0:0 Mixer rec ...
-
09.01.11Adding formatting to an XML documentSometimes, when I have to program a web service client I have to deal with unformatted XML files. For example, the next one: <users><user><email>pfortuny@commandliners.com</email><passwd>a0f901492d89fe2ba88cc96bf9d 2475e</passwd></user><user><email>n0str0m0@commandliners.com</email><passwd>7e1b6dbfa824d 5d114e96981cededd00</passwd></user><user><email>rafacas@commandliners.com</email><passwd> 70c1db56f301c9e337b0099bd4174b28</passwd></user></users> This is not a bad thing, because it is sent that way to save traffic, but I'd rather see it in a human readable format. So I use the xmllint command, that reformat and reindent the input. $ xmllint --format test.xml <?xml version="1.0"?> <users> <user> <email>pfortuny@commandliners.com</email> <passwd>a0f901492d89fe2ba88cc96bf9d2475e</passwd> </user> <user> <email>n0str0m0@commandliners.com</email> <passwd>7e1b6dbfa824d5d114e96981cededd00</passwd> </user> <user> <email>rafacas@commandliners.com</email> <passwd>70c1db56f301c9e337b0099bd4174b28</passwd> </user> </users> The indentation can be controlled by the environment variable XMLLINT_INDENT. The default value is two spaces. pfortuny, n0str0m0, do not worry guys, those are not your ...
-
08.18.11Determining if an XML document is well-formedAfter creating an XML document from scratch I always check if it is well-formed. This means it must adhere to a number of rules, including the following: Every start-tag must have a matching end-tag. Elements may nest, but may not overlap. There must be exactly one root element. Attribute values must be quoted. An element may not have two attributes with the same name. This is not an exhaustive list and I do not mean to explain all the rules. There are many, many ways a document can be malformed. But if you need to determine if and XML document is well-formed there is a linux ...
-
07.21.11Printing sequential numbers in BSDIn Linux, the seq command is pretty useful in some scripts, because it prints a sequence of numbers: $ seq 1 5 1 2 3 4 5 It is usually used in for loops: for i in `seq 1 5`; do ... done But this command is not included in BSD-like OSes. It is contained in the sh-utils, so one option is downloading and compiling it. But I prefer using the commands that come by default with the OS, for portability. In the BSD case, I found the jot command that prints sequential or random data. The following example shows the seq behaviour with jot. $ jot 5 1 2 3 4 5 Other example ...