Batch unzip 7z archives

Posted by marian on June 06, 2010

  1. #!/bin/bash
  2. for i in $(find $(pwd) -name '*.7z')
  3. do
  4.        cd $(dirname $i)
  5.        7z x  $i
  6. done

Batch unrar archives

Posted by marian on June 06, 2010

  1. #!/bin/bash
  2. for i in $(find $(pwd) -name '*.rar')
  3. do
  4.        cd $(dirname $i)
  5.        unrar e  $i
  6. done

Batch unzip archives

Posted by marian on June 06, 2010

  1. #!/bin/bash
  2. for i in $(find $(pwd) -name '*.zip')
  3. do
  4.        cd $(dirname $i)
  5.        unzip  $i
  6. done

Strange errors when compiling Erlang R1304 on NetBSD

Posted by marian on June 03, 2010

Well I dindn’t expect this. If you are trying to compiler Erlang on this OS, this might save you some time.

If you get the the following error sequence:


make: "/home/acces/otp_src_R13B04/Makefile" line 88: Missing dependency operator
make: "/home/acces/otp_src_R13B04/Makefile" line 89: Missing dependency operator
make: "/home/acces/otp_src_R13B04/Makefile" line 91: Need an operator
make: "/home/acces/otp_src_R13B04/Makefile" line 92: Need an operator
make: "/home/acces/otp_src_R13B04/Makefile" line 93: Missing dependency operator
make: "/home/acces/otp_src_R13B04/Makefile" line 94: Missing dependency operator
make: "/home/acces/otp_src_R13B04/Makefile" line 95: Need an operator
make: "/home/acces/otp_src_R13B04/Makefile" line 96: Need an operator
make: "/home/acces/otp_src_R13B04/Makefile" line 97: Need an operator
make: "/home/acces/otp_src_R13B04/Makefile" line 98: Need an operator
make: "/home/acces/otp_src_R13B04/Makefile" line 159: Need an operator
make: "/home/acces/otp_src_R13B04/Makefile" line 164: Missing dependency operator
make: "/home/acces/otp_src_R13B04/Makefile" line 166: Need an operator
make: "/home/acces/otp_src_R13B04/Makefile" line 167: Missing dependency operator
make: "/home/acces/otp_src_R13B04/Makefile" line 169: Need an operator
make: "/home/acces/otp_src_R13B04/Makefile" line 171: Need an operator
make: "/home/acces/otp_src_R13B04/Makefile" line 172: Need an operator
make: "/home/acces/otp_src_R13B04/Makefile" line 202: Need an operator
make: "/home/acces/otp_src_R13B04/Makefile" line 217: Missing dependency operator
make: "/home/acces/otp_src_R13B04/Makefile" line 220: Need an operator
make: "/home/acces/otp_src_R13B04/Makefile" line 222: Need an operator
make: "/home/acces/otp_src_R13B04/Makefile" line 228: Cannot open /home/acces/otp_src_R13B04/make//otp_ded.mk
make: "/home/acces/otp_src_R13B04/Makefile" line 250: Missing dependency operator
make: "/home/acces/otp_src_R13B04/Makefile" line 254: Missing dependency operator
make: "/home/acces/otp_src_R13B04/Makefile" line 256: Need an operator
make: "/home/acces/otp_src_R13B04/Makefile" line 258: Need an operator
make: "/home/acces/otp_src_R13B04/Makefile" line 268: Missing dependency operator
make: "/home/acces/otp_src_R13B04/Makefile" line 270: Need an operator
make: "/home/acces/otp_src_R13B04/Makefile" line 272: Need an operator
make: "/home/acces/otp_src_R13B04/Makefile" line 276: Missing dependency operator
make: "/home/acces/otp_src_R13B04/Makefile" line 277: Missing dependency operator
make: "/home/acces/otp_src_R13B04/Makefile" line 279: Need an operator
make: "/home/acces/otp_src_R13B04/Makefile" line 280: Need an operator
make: "/home/acces/otp_src_R13B04/Makefile" line 287: Missing dependency operator
make: "/home/acces/otp_src_R13B04/Makefile" line 288: Missing dependency operator
make: "/home/acces/otp_src_R13B04/Makefile" line 290: Need an operator
make: "/home/acces/otp_src_R13B04/Makefile" line 292: Need an operator
make: "/home/acces/otp_src_R13B04/Makefile" line 293: Need an operator
make: "/home/acces/otp_src_R13B04/Makefile" line 305: Missing dependency operator
make: "/home/acces/otp_src_R13B04/Makefile" line 308: Missing dependency operator
make: "/home/acces/otp_src_R13B04/Makefile" line 310: Need an operator
make: "/home/acces/otp_src_R13B04/Makefile" line 313: Need an operator
make: "/home/acces/otp_src_R13B04/Makefile" line 315: Need an operator
make: "/home/acces/otp_src_R13B04/Makefile" line 320: Need an operator
make: "/home/acces/otp_src_R13B04/Makefile" line 337: Missing dependency operator
make: "/home/acces/otp_src_R13B04/Makefile" line 344: Need an operator
make: "/home/acces/otp_src_R13B04/Makefile" line 360: Missing dependency operator
make: "/home/acces/otp_src_R13B04/Makefile" line 363: Need an operator
make: "/home/acces/otp_src_R13B04/Makefile" line 365: warning: duplicate script for target "noboot" ignored
make: "/home/acces/otp_src_R13B04/Makefile" line 362: warning: using previous script for "noboot" defined here
make: "/home/acces/otp_src_R13B04/Makefile" line 366: Need an operator
make: "/home/acces/otp_src_R13B04/Makefile" line 373: Missing dependency operator
make: "/home/acces/otp_src_R13B04/Makefile" line 377: Need an operator
make: "/home/acces/otp_src_R13B04/Makefile" line 381: Missing dependency operator
make: "/home/acces/otp_src_R13B04/Makefile" line 391: Need an operator
make: "/home/acces/otp_src_R13B04/Makefile" line 392: Need an operator
make: "/home/acces/otp_src_R13B04/Makefile" line 401: Missing dependency operator
make: "/home/acces/otp_src_R13B04/Makefile" line 403: warning: duplicate script for target "ifeq" ignored
make: "/home/acces/otp_src_R13B04/Makefile" line 376: warning: using previous script for "ifeq" defined here
make: "/home/acces/otp_src_R13B04/Makefile" line 403: warning: duplicate script for target "(,true)" ignored
make: "/home/acces/otp_src_R13B04/Makefile" line 376: warning: using previous script for "(,true)" defined here
make: "/home/acces/otp_src_R13B04/Makefile" line 404: Need an operator
make: "/home/acces/otp_src_R13B04/Makefile" line 409: Need an operator
make: "/home/acces/otp_src_R13B04/Makefile" line 441: Missing dependency operator
make: "/home/acces/otp_src_R13B04/Makefile" line 442: warning: duplicate script for target "ifneq" ignored
make: "/home/acces/otp_src_R13B04/Makefile" line 390: warning: using previous script for "ifneq" defined here
make: "/home/acces/otp_src_R13B04/Makefile" line 443: Need an operator
make: "/home/acces/otp_src_R13B04/Makefile" line 447: Need an operator
make: "/home/acces/otp_src_R13B04/Makefile" line 463: Missing dependency operator
make: "/home/acces/otp_src_R13B04/Makefile" line 466: warning: duplicate script for target "ifeq" ignored
make: "/home/acces/otp_src_R13B04/Makefile" line 376: warning: using previous script for "ifeq" defined here
make: "/home/acces/otp_src_R13B04/Makefile" line 466: warning: duplicate script for target "(,true)" ignored
make: "/home/acces/otp_src_R13B04/Makefile" line 376: warning: using previous script for "(,true)" defined here
make: "/home/acces/otp_src_R13B04/Makefile" line 467: Need an operator
make: "/home/acces/otp_src_R13B04/Makefile" line 471: Need an operator
make: "/home/acces/otp_src_R13B04/Makefile" line 493: Missing dependency operator
make: "/home/acces/otp_src_R13B04/Makefile" line 502: warning: duplicate script for target "ifneq" ignored
make: "/home/acces/otp_src_R13B04/Makefile" line 390: warning: using previous script for "ifneq" defined here
make: "/home/acces/otp_src_R13B04/Makefile" line 502: warning: duplicate script for target "(,true)" ignored
make: "/home/acces/otp_src_R13B04/Makefile" line 376: warning: using previous script for "(,true)" defined here
make: "/home/acces/otp_src_R13B04/Makefile" line 503: Need an operator
make: "/home/acces/otp_src_R13B04/Makefile" line 530: Missing dependency operator
make: "/home/acces/otp_src_R13B04/Makefile" line 542: Need an operator
make: "/home/acces/otp_src_R13B04/Makefile" line 558: Need an operator
make: "/home/acces/otp_src_R13B04/Makefile" line 972: Missing dependency operator
make: "/home/acces/otp_src_R13B04/Makefile" line 975: warning: duplicate script for target "ifeq" ignored
make: "/home/acces/otp_src_R13B04/Makefile" line 376: warning: using previous script for "ifeq" defined here
make: "/home/acces/otp_src_R13B04/Makefile" line 975: warning: duplicate script for target "(,true)" ignored
make: "/home/acces/otp_src_R13B04/Makefile" line 376: warning: using previous script for "(,true)" defined here
make: "/home/acces/otp_src_R13B04/Makefile" line 976: Need an operator
make: "/home/acces/otp_src_R13B04/Makefile" line 989: Need an operator
make: Fatal errors encountered -- cannot continue

make: stopped in /home/acces/otp_src_R13B04

then the easy solution to overcome it is to build Erlang with :

Another issue:

The only solution that I found was at http://mail-index.netbsd.org/pkgsrc-bugs/2007/11/11/msg025712.htm.

Basically you have to run config & gmake.

Starting Erlang at NetBSD boot up

Posted by marian on April 16, 2010

This would do the job:

vi /etc/rc.d/erlang.sh

  1. #!/bin/sh
  2. case $1 in
  3. start)
  4.         /usr/pkg/bin/erl -Pa /home/user/path_to_your_applications +A 5 -remsh -name e1@192.168.1.5 -heart -detached  -setcookie "mycookie" &
  5.         ;;
  6. stop)
  7.         killall erl
  8.         ;;
  9. esac

Convert all *.ppt files in a directory to *.pdf (or any format suported by OpenOffice to PDF)

Posted by marian on January 20, 2010

I believe that everybody came across the need to convert some Microsoft Office document into PDF format. Under GNU/Linux this can be accomplished very simply.
If you are a student and all the courses are in PowerPoint and you want to read them as PDF under GNU/Linux using the awesome evince, then you will appreciate this tutorial. ( Question to the reader: Why does Evince look so good, while the GNU/Linux version of Acrobat Reader is so sluggish ?)
Steps to follow:
1) Install OpenOffice
2) Install Cups-PDF:

  1. sudo apt-get install cups-pdf (Ubuntu)
  2. sudo yum install cups-pdf (Fedora)

3) Create a PDF directory in your home directory if it doesn’t exist:

  1. mkdir ~/PDF

4) For converting a single *.ppt file to *.pdf you should use:

  1. soffice -norestore -nofirststartwizard -nologo -headless -pt PDF your_pdf_file.ppt

But this can be achieved easily using OpenOffice GUI.
Now I will show you how easy is to convert all the files in a directory to PDF files and then merge them in a single PDF file. You just have to go to the directory containing your files and then execute :

  1. find . -type f -name "*.ppt" -exec soffice -norestore -nofirststartwizard -nologo -headless -pt PDF {} \;

Find will search in the current directory for all the files (due to “-type f”) and having the extension ppt (due to -name “*.ppt”) and convert them into PDF files.
You might also use *.doc (Microsoft Word), and i think (not tested) that also *.pptx and *.docx (Microsoft Office 2007) could be used. The output files will be stored in the ~/PDF directory.

Now the PDF merging stage. There are many tools that can do this under Linux, but I prefer pdftk which can be installed using:

  1. sudo apt-get install pdftk (Ubuntu)
  2. sudo yum install pdftk (Fedora)

And here is the easiest way to merge all the PDF files in a directory:

  1. pdftk *.pdf output merged.pdf

where merged.pdf is the name of the merged file :) ).

Java Server Faces form validators

Posted by marian on November 01, 2009

There are three clear trends towards building web-pages these days: PHP, ASP, and JSP / JSF / Struts.
This post addresses the problem of writing custom data validators for web forms.
Validators are introduced in JSF pages by the “validator” tag, a custom input field looking like:

The name of the validator is given by the validatorId.

The mapping between the validatorId and the class handling the validation is done through the faces-config.xml.
<?xml version=’1.0′ encoding=’UTF-8′?>
<faces-config version=”1.2″
xmlns=”http://java.sun.com/xml/ns/javaee”
xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance”
xsi:schemaLocation=”http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_1_2.xsd”>
<managed-bean>

</managed-bean>

<navigation-rule>
<from-view-id> … </from-view-id>
<navigation-case>
<from-outcome>…</from-outcome>
<to-view-id>…</to-view-id>
</navigation-case>
</navigation-rule>

<validator>
<validator-id>NameValidator</validator-id>
<validator-class>NameValidator</validator-class>
</validator>
</faces-config>
The name validator is backed up by some Java code, that handles the corresponding validation. Basically a custom field validator implements the marker interface javax.faces.validator.Validator, having a single method called validate. The data is passed to our validating class through the mediation of the “value” object, which has to be cast to the type we are expecting it to be. To offer greater flexibility I created an Abstract Class which handles all the JSF’s API calls, which is latter implemented by a concrete class.

  1. import javax.faces.application.FacesMessage;
  2. import javax.faces.component.UIComponent;
  3. import javax.faces.context.FacesContext;
  4. import javax.faces.validator.Validator;
  5. import javax.faces.validator.ValidatorException;
  6.  
  7. public abstract class AbstractValidator implements Validator{
  8.  
  9.     public abstract boolean validValue(String text);
  10.     public abstract String getErrorMessage();
  11.  
  12.     public void validate(FacesContext context, UIComponent component,
  13.             Object value) {
  14.  
  15.         if (value == null) return;
  16.  
  17.         String text = value.toString();
  18.  
  19.         if (!validValue(text)) {
  20.              FacesMessage message = new FacesMessage(
  21.                         FacesMessage.SEVERITY_ERROR,
  22.                         getErrorMessage(), null);
  23.                 throw new ValidatorException(message);
  24.         }
  25.     }
  26. }

The concrete class adapts our abstract validator to our needs :

  1. public class NameValidator extends AbstractValidator {
  2.  
  3.     private char prohibited[] = {'/', '.'};
  4.     private static String ERROR_MESSAGE = "Invalid name format.";
  5.  
  6.     @Override
  7.     public String getErrorMessage(){
  8.         return ERROR_MESSAGE;
  9.     }
  10.  
  11.      @Override
  12.     public boolean validValue(String text) {
  13.         if (text.length()==0) {
  14.              return false;
  15.         }
  16.         for (int i = 0; i &lt; prohibited.length; i++) {
  17.             if (text.indexOf(prohibited[i]) != -1) {
  18.                 return false;
  19.             }
  20.         }
  21.         return true;
  22.     }
  23. }