Setup an SVN Repo server

I had to setup an SVN Repo server today, but I couldn’t. I’ve been working below pressure. And I believe that interrupted me from doing great work.

I believe, working below pressure is not always a good idea, it diminishes performance. I couldn’t setup an SVN repo today, but after I tried out later, it was very easy.

In order to document what I did, I’m writing this post.

Steps to setup

  1. Create your repo with:
    $ svnadmin create /path/to/your/repo
  2. Enable some conf to give access to other users to your repo
    1. Edit /pathYourRepo/conf/svnserve.conf
      anon-access = none      # anonymous acess
      auth-access = write     # authenticate acess

      We are giving none access to anonymous users and write to others. You can also use just read access.

      password-db = passwd

      Indicate the file path for the password file. In this case, it is a relative file in the same directory where the svnserve.conf is.

    2. Edit /pathYourRepo/conf/passwd file and add users and passwords.
      carlosuser = carlospassword
  3. Organize your repo project. You can create a separate file for each project and create the structure you want (trunk, branches, tags, and so forth).You can add directories to your repo:
    $ svn mkdir /full/path/to/your/repo/newDirectory

    Or you can import a project into your repo.

    $ svn import /path/to/project file:///full/path/to/repo

    You will need to provide a message to commit that changes.

  4. Start the svn server
    $ svnserve -d -r /path/to/your/repo

Test your repo

Now that you have configured your own repo, you might want to checkout your project. That is easy too:

$ svn checkout svn://localhost/pathRepo

First, you will be asked to provide the user realm (no idea what is that) but just left blank and press intro, then you will be asked the username and password you created. That’s all, you should have your project at you new path and any changes you make should be centralized into your server.

For more information about Subversion, this link will be useful.

Posted in Subversion | Tagged | Leave a comment

Cabal: Manual Installation & Configuration

Today I wanted to spent some of my time installing and configuring Cabal;
I recently installed the new version of GHC (7.6.1) for Archlinux, and cabal suggested me to update my cabal package from 1.10 to a newer version. But, when I was trying to install it (cabal install cabal-install), I got an error.

cabal install cabal-install
...
Resolving dependencies...cabal: Couldn't read cabal file "hashable/1.2.0.0/hashable.cabal"
...

Well, I searched a little on the web, and I found that I have to install it manually, so I downloaded the newer version of Cabal from Hackage and tried to install it again.

./bootstrap.sh

However, I got another error again. This time, it was a compilation error on the package HTTP, on the file Auth.hs, something with URL’s.

Trying to fix it manually, I noticed that the bootstrap.sh was installing the version 2.4 of HTTP but there were a newer 2.6 version. So I changed to the new one and worked it out.

The next steps was to configure cabal. It is not needed for normal use, but personally I prefer that cabal installs my packages on /usr/local/bin and not below my user (~/.cabal/). And also I want cabal to generate the documentation automatically, etc. So a few changes on the cabal config file (~/.cabal/config) is needed.

First, global installation: just uncomment some fields

user-install: False
root-cmd: sudo

For documentation

documentation: True
doc-index-file: $datadir/doc/index.html

You will also need to install the package haddock (cabal install haddock) for documentation.
One thing I don’t know but I would like, is to automatically generate hscolour output on the documentation. It would be wonderful to have all packages with his colored code available on documentation.

That’s all I think.

PS: Don’t forget to do cabal update right after installing cabal.

Posted in cabal, haskell | Tagged , , | Leave a comment

Weird error on executing Java programs

Today, I had a weird error on executing a simple Java program (I have to confess that I didn’t use Java for some time ago :D). Suppose you got a HelloWorld.java file in which you just print the “Hello World!” message; after compiling that successfully, you want to execute it, but the compiler cry telling you that she can’t find or load the main class.

> java HelloWorld
> Error: no se ha encontrado o cargado la clase principal HelloWorld

What a weird error!!

First, I suppose that the class I have defined wasn’t Public, so I changed it as a Public Class, however it doesn’t work.

Then, after pondering it for a while, I thought of some path problem. I review carefully the path of the compiler, it was ok. Anyway I went to the root of the Java bin directory and recompile and rerun it again. mmmmm The problem stayed there. Then I said again “What a weird error”. :/

I don’t remember having these problems when I was learning Java. The only thing I remember was to avoid the .class extension of the compiled java file in order to execute it with the java command.

Finally the light came to me and I said: If she can’t find it, maybe she is finding it in the wrong place, so let’s give her a little more information of the environment. Then, I searched for some console arguments for setting the environment and I found the java -cp argument (ClassPath):

> java -cp . HelloWorld

And it worked.

In conclusion, personally I think that it was a weird error because I don’t remember having these problems before. And mainly and mostly because I think that the home directory of the file that someone is trying to execute must be the default directory of the classpath. So we don’t have to set -cp . argument.
Well, I don’t know if this error happened only to me, not sure whether it was the same before or since when it changed.

Posted in Compiler, Java | Tagged , | Leave a comment

Instalar wxHaskell 0.90 en Windows 7

Recientemente publicaron la versión 0.90 de wxHaskell(2da semana de Abril), la cual trabaja con wxWidgets 2.9.x, anteriormente trabajaba con la versión 2.8. Desde entonces, he estado con cierto interés en probar las nuevas características.

Bueno, instalar wxHaskell en linux es relativamente sencillo (aquí Antonio muestra los pasos), pero instalarlo en Windows 7 ha sido todo un desafió para mi, y me gustaría compartir una serie de pasos y comentarios para facilitar la vida a otros.

WxHaskell es una librería gráfica para hacer GUI’s en Haskell(la forma fácil de obtener Haskell es a través del Haskell Platform); WxHaskell utiliza como librería base al conocido WxWidgets (WxHaskell es algo así como un ‘wrapper’ de WxWidgets). Y para probarlo necesitaremos instalar WxWidgets primero, ademas en Windows necesitaremos de MinGW para compilar el WxWidgets. Entre otras cosas, también necesitaremos el wx-config, una herramienta de linea de comandos que ayuda en la compilación de codigo wxWidgets.

Les comparto los pasos que hice para instalar el WxWidgets:

  1. Descargar e instalar el MinGW. Yo me descargue la ultima versión desde aquí. He seleccionado las opciones del compilador de C++ y el MinGW Developer Toolkit, así como lo recomienda Sky TreeBird en su tutorial. No olvidar añadir al path de Windows el directorio ‘bin’ del MinGW instalado.
  2. Descargar e instalar el wx-config. Yo he tenido varias dificultades aquí. Encontré varias copias de esta herramienta, y algunas de ellas impidieron que se compile bien el WxWidgets. Yo recomiendo que se descarguen el código fuente de wx-config desde aqui. Y luego lo compilan de esta manera (obtenido de WikiHaskell):
    g++ wx-config.cpp -o wx-config.exe

    Luego podrían copiar el .exe generado a un lugar publico en su pc y visible desde el cmd (añadir la dirección de .exe al path de variables publicas de windows).

    Lo otro que pueden hacer, pero que no lo he probado, es descargar el .exe directamente de aquí.

    Para probar si funciona bien su wx-config, pueden hacer wx-config –help en la consola. En varios casos a mi me salio un error feisimo de la aplicación.

  3. Configurar variables de entorno. Se necesitará configurar las siguientes variables recomendadas por el WikiHaskell:
    • CABAL_DIR: C:\Users\XXX\AppData\Roaming\cabal
    • GHC_VERSION: 7.0.4 (o la que tengas en sus maquinas)
    • WXC_VERSION: 0.90.0.2
    • WXWIN: C:\wxWidgets-2.9.3 (o el lugar donde descargaran el WxWidgets)
    • WXCFG: gcc_dll\mswu
    • PATH: (add these) %WXWIN%\lib\gcc_dll;%WXWIN%;%CABAL_DIR%\wxc-%WXC_VERSION%\%GHC_VERSION%
  4. Descargar e instalar WxWidgets 2.9.3. Descargan las fuentes desde aquí, y lo compilan siguiendo las instrucciones del Readme.txt, yo lo hice así:
    cd c:\wx\build\msw
    mingw32-make -f makefile.gcc BUILD=debug

    Esto tomará nomas bastante tiempo. Luego, es importante probar algún ejemplo de wxWidgets. Hay varios ejemplos para ver. Yo solo seguí el Readme.txt para probar los ejemplos:

    cd c:\wx\samples\minimal
    mingw32-make -f makefile.gcc BUILD=debug

Hasta aquí ya se hizo gran parte de la instalación, :).

end installed wxwidgets

Lo que ahora sigue es instalar WxHaskell. Para ello, nos beneficiaremos de cabal, el cual ya viene instalado en el Haskell Platform (por si acaso hacer cabal update) y el mismo que se encargará de resolver todas las dependencias con un simple comando, que super!, :).

cabal install wx

Algunas recomendaciones necesarias:

  • Error de UTF-8.
    :0:5: lexical error (UTF-8 decoding error)
    cabal: Error: some packages failed to install:
    strict-0.3.2 failed during the building phase. The exception was:
    ExitFailure 1
    wxdirect-0.90.0.1 depends on strict-0.3.2 which failed to install.

    Es arreglado colocando en la consola set LANG=C.

  • Error de que faltan algunas librerias
    Missing dependencies on foreign libraries:
    * Missing C libraries: wxmsw29ud_all, wxtiffd, wxjpegd, wxpngd, wxzlibd, wxregexud, wxexpatd, wxregexud
    This problem can usually be solved by installing the system packages that
    provide these libraries (you may need the “-dev” versions). If the libraries
    are already installed but in a non-standard location then you can use the
    flags –extra-include-dirs= and –extra-lib-dirs= to specify where they are.
    cabal: Error: some packages failed to install:
    wxc-0.90.0.2 failed during the configure step. The exception was:
    ExitFailure 1

    Es arreglado descargando el wx-config desde aquí. Descargar el .exe y reemplazarlo por el que tenias.

  • Otras recomendaciones las puedes encontrar en el WikiHaskel.

Probando WxHaskell.
Para probar, instalemos un pequeño juego:

cabal install wxAsteroids

Después de instalarlo, cuando se intenta ejecutar el juego, a mi me apareció un error de que no encuentra el archivo wxc.dll. Ese archivo lo encontre en C:\Users\XXX\AppData\Roaming\cabal\wxc-0.90.0.2\ghc-7.0.4 y luego lo copie a un lugar publico para Windows, o en la misma carpeta de donde se esta llamando al programa.

Para terminar, le dejo con la imagen del juego instalado. Y a disfrutar con WxHaskell.

wxasteroids

Posted in wxHaskell | Tagged , , | Leave a comment

Prime number generator

Someone ask for a function that generates the prime numbers between two limits [1 and N given by the user], but he forgot to specify the time execution.

I write this first function in haskell:

module Main where

main :: IO()
main = interact function

function :: String -> String
function = unlines . map show . concat . map process . lines

process :: String -> [Integer]
process snum = let num = toInt snum
                      in [i | i  <- filter isPrime [2..(num-1)] ]

isPrime :: Integer -> Bool
isPrime n = and $ map (\i -> n `mod` i /= 0) [2..(n-1)]

toInt :: String -> Integer
toInt = read

The input to try is a list of natural numbers contained in a file.
If we try with 100000 it will take:
real 0m36.796s
user 0m36.521s
sys 0m0.167s

Trying with another version of isPrime:

isPrime :: Integer -> Bool  
isPrime n = (==) [] $ filter (\i -> mod n i == 0) [2..floor (n'/log n')]
       where n' = fromInteger n

Now, there is a big diference!!
real 0m4.647s
user 0m4.556s
sys 0m0.033s

Trying another function for isPrime:

isPrime :: Integer -> Bool
isPrime n = (==) [] $ dropWhile (\i -> mod n i /= 0) [2..floor (n' / log n')]
    where n'    = fromInteger n

But his time is the same, even sometimes is more.

I think the last should take less time, because dropWhile not always walk all the list, but filter always walk all the list. I don’t understand what’s happening.

Trying with another function for isPrime:

isPrime :: Integer -> Bool
isPrime n = (==) [] $ dropWhile (\i -> mod n i /= 0) [2..floor (sqrt n')]
    where n'    = fromInteger n

This version has a direfferent rank: sqrt n, and his time execution is also less:
real 0m0.492s
user 0m0.457s
sys 0m0.033s

Ok, i will return in another lazy time …

Posted in haskell | Tagged , , , | 1 Comment