Author

The Archives

  • 27.Mar.13
    Limit running time to a program shell | pfortuny | (0)
    There is no obvious way to specify that a program should run for no longer than x seconds. The following stackoverflow question solves it in a very perlish-way. Define a helper function doalarm: $ doalarm () { perl -e 'alarm shift; exec @ARGV' "$@"; } # define a helper function And you are done. $ doalarm 300 ./my_prog will run for at most 300 seconds.
  • 19.Feb.13
    Use of find with regular expressions automated, scripts, shell | pfortuny | (0)
    I found myself needing to write a clean: rule in a makefile which would wipe out all the auxiliary files generated by latex (among other things). Moreover, the project has some subdirectories in which there might be more of those files. Apart from finding files by date, size, modification time... the find utility can use regular expressions. I am not delving a lot into this (what kind of expressions, etc.), I just wanted to point out two things: That it comes in quite handy. That the regex must match the complete file name as reported by find. The second item is worth noticing. If ...
  • 25.Oct.12
    utf-8 blues in snow leopard with mutt and vim shell | pfortuny | (0)
    Yes, it looks like a true spam page. But it is the only way to describe my problem. I was trying to set up mutt (yes, I am a bit fed up with Mail.app and its inability to be controlled with the keyboard alone in any sensible way). Terminal.app seems to work OK with utf-8. However, the included vim does not. Any time you type an accented char and delete it, the text gets mangled (you know, typical off-by-one cursor position). The solution for vim is incredibly stupid: open up vim and write :set encoding=utf-8 (or do that at any ...
  • 17.Mar.12
    Text manipulation on UNIX cmd | pfortuny | (0)
    A quick link to IBM's introduction to text utilities on UNIX. They know the stuff.
  • 12.Nov.11
    Unicode sorting in perl shell | pfortuny | (0)
    Just 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).
  • 08.Jul.11
    Script for making an ordered list of files shell | pfortuny | (0)
    You've got a bunch of files you want to reorder (that is rename so that they appear in a specific order) but do not want to really rename them (their original names are relevant). You may want to create a set of links to each of them with the appropriate '001', '002' term before. Here is a script for doing exactly this. Use as follows (if named 'mapnames.sh'): $ mapnames.sh digits file1 [file2 file3 ...] will use digits digits for the leading numeral (adding '0' before) and will link the files in the given order. Here is the code: #!/bin/sh length=$1 shift count=1 for name in $@ do ...
  • 28.Jun.11
    The Sibyl going to the No cON Name network, news, security | pfortuny | (0)
    Both rafacas and pfortuny are going next September to Barcelona to the No cON Name conference, to talk about The Sibyl, of which we have already written here. If any of you is interested in IT Security and can make it to Barcelona in September (14-17), it would be nice to meet you there.
  • 22.Feb.11
    Learning to write (GNU) makefiles automated, scripts, shell | pfortuny | (0)
    I am a Mathematician and usually write more LaTeX than C but programming has been an active hobby since I owned my first Spectrum back in the eighties. What I am commenting in this post has been plaguing me for years and I have just learnt it (from laziness, no more): using pattern rules in makefiles. Caveat: I do not know whether this works for non-GNU Makes or not. I had already read a lot of pro makefiles, which contained endless funny codes like $@, $%, $< etc. Today I have learnt the meaning of some of these. I am supervising a ...
  • 18.Feb.11
    Moving between encodings with emacs automated, scripts, shell | pfortuny | (0)
    I live in Spain. I work at Academia. This is a problem. My School's computers are plagued with Windows (XP!), my pupils most certainly use Windows (I bet it is 7) and I use (obviously) an MBPro with Snow Leopard. Even more, my School's servers are Linux. This gives rise to latin-1, UTF-8 collisions. While writing some text-only documents for use with MATLAB (another problem, by the way) I realized I was going to need to convert them from my Mac's UTF-8 to Windows latin-1 every time I edited them. Time for a makefile. I am not commenting this though, only the ...
  • 08.Dec.10
    The savannah.gnu incident and the Sibyl news, security | pfortuny | (0)
    The savannah.gnu.org compromise in December 2010 is another example of the weakness of system passwords: there will always be someone using a brute-force attackable key. And that is the weakest link. I just want to point out to all our readers out there that the Sibyl is precisely an idea to implement a secure way to store hashes of passwords and prevent brute-force attacks. It is not computationally cheap or even the simplest of setups, but security has a price. At least, it is, but for the hardware part, which depends on your implementation, 'gratis' and BSD-licenced. Hope you like it.