Archive for the ‘linux’ Category

trac-accountmanager in debian

Friday, August 7th, 2009

This advice is probably too late for you but: Don’t install the package trac-accountmanager in debian, seems broken. Install the plugin directly with “sudo easy-install …” as described in track-hacks.org
Corolary: why I’m using ArchLinux? Speed. And also because I have about an 80% less packages installed by hand. Also I can contrib easily with new packages in AUR.

JSP Hello World Howto

Thursday, August 6th, 2009

This can be called a howto of “How can I make a hello world in JSP without unnecessary tools like, Eclipse, struts, servlets, JBoss, etc.?” only you, your text editor, tomcat and of course, your GNU-Linux box.

1. Create a directory anywhere to store your app, let’s create one called “myapp”: mkdir myapp

2. Create your hello.jsp web page: echo ‘<% String hello=”Hello World”; %><%=hello%>’ > myapp/hello.jsp

3. Create your app’s web.xml file, you should have this file under (create it) the WEB-INF directory, under “myapp”:

<?xml version=”1.0″ encoding=”ISO-8859-1″?>
<web-app xmlns=”http://java.sun.com/xml/ns/j2ee”
xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance”
xsi:schemaLocation=”http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd”
version=”2.4″>
<display-name>Hello World</display-name>
<description>My hello world app.</description>
<welcome-file-list>
<welcome-file>hello.jsp</welcome-file>
</welcome-file-list>
</web-app>

4. Install tomcat, for example, in Arch I’ve typed: sudo pacman -Sy tomcat

5. Make your app. available: sudo ln -s /path/to/myapp /opt/tomcat/webapps

6. Start tomcat, for example, in arch I’ve typed: sudo /etc/rc.d/tomcat start

7. Point your browser to: localhost:8080/myapp

Python: using a module written in C

Tuesday, June 9th, 2009

This is a brief tutorial for using a module written in C inside a Python program. It’s a summarized recipe fr those who want to run and test something fast without falling in reading the docs, but I recommend to read.

[1] http://docs.python.org/extending/extending.html
[2] http://docs.python.org/extending/building.html

Let’s write a module called spam, the same as the example in [1], our spammodule.c will look like this:

#include 
static PyObject *SpamError;
static PyObject *
spam_system(PyObject *self, PyObject *args){
    const char *command;
    int sts;
    if (!PyArg_ParseTuple(args, “s”, &command))
        return NULL;
    sts = system(command);
    return Py_BuildValue(”i”, sts);
}
static PyMethodDef SpamMethods[] = {
    {”system”,  spam_system, METH_VARARGS,
     “Execute a shell command.”},
    {NULL, NULL, 0, NULL}        /* Sentinel */
};
PyMODINIT_FUNC
initspam(void){
    PyObject *m;
    m = Py_InitModule(”spam”, SpamMethods);
    if (m == NULL)
        return;
    SpamError = PyErr_NewException(”spam.error”, NULL, NULL);
    Py_INCREF(SpamError);
    PyModule_AddObject(m, “error”, SpamError);
}

Ok, now, rather than compiling it by hand, let’s use an automated mechanism: distutils [2]. Edit a setup.py file which will be the “driver” for compile and make yur module in C importable from Python.

from distutils.core import setup, Extension
module1 = Extension('spam', sources = ['spammodule.c'])
setup(name = ‘PackageName’, version = ‘1.0′, description = ‘This is a demo package’,
          ext_modules = [module1])

Compile the C module using the driver: $ python setup.py build
An example of the output I get:

running build
running build_ext
building 'spam' extension
creating build
creating build/temp.linux-x86_64-2.6
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python2.6 -c spammodule.c -o build/temp.linux-x86_64-2.6/spammodule.o
creating build/lib.linux-x86_64-2.6
gcc -pthread -shared build/temp.linux-x86_64-2.6/spammodule.o -L/usr/lib -lpython2.6 -o build/lib.linux-x86_64-2.6/spam.so

Test it!, depending on your platform and settings you’ll get a directory tree created, I’ll cd into mine:

$ cd build/lib.linux-x86_64-2.6
$ python
>>> import spam
>>> spam.system('echo "hello world"')
hello world
0
>>>

Python2.6 with mod_python in debian

Thursday, January 15th, 2009

As you may know, there are no packages yet for Python2.6 in debian or ubuntu. If you want to install it you can do it by hand and it will work perfectly (it did for me)

Google a bit and you will find this post: http://blog.pythonaro.com/2008/10/horrible-hack-to-get-python-26-on.html

You can follow the steps in the post without problem, then remember to update your supported and default versions under /usr/share/pyhton/debian_defaults

Also you can link modules available in 2.5 to be used by 2.6, for example Ipython, it works perfectly. Do symlinks from python2.6/site_packages/ pointing python2.5/site_packages. Although this is not the correct way, the correct way should be reinstall those modules under your new configuration.

But what about mod_python? it still remains to Python2.5 right? YES

Well, you have to do the same, download it from modpython.org and make and make install, be sure to install apache2-dev it will provide you with a tool needed in the compilation time.

All should work, also django is working perfectly in my new Python & mod_python 2.6 conf. under debian.

cheers!

How to encrypt your USB extarnal devices

Saturday, October 11th, 2008

based and thanks to http://feraga.com/node/51

FIRST: detect your device name using dmesg (you should be familiar with this). For example, in my company they bought a comstar 160GB usb external device, and I see it under /dev/sdc1

# Install cryptsetup with LUKS (under linux2.6)
apt-get install cryptsetup

# Create the encrypted partition
cryptsetup luksFormat /dev/sdc1

# Map it to a device mapper
cryptsetup luksOpen /dev/sdc1 comstar

# Give it a FS of your choice
mkfs.ext3 /dev/mapper/comstar

# Make the mount point and mount the device
mkdir /media/comstar
mount /dev/mapper/comstar /media/comstar

# That’s all? -yes. Now, just for test:

# Umount the device
umount /media/comstar

# Close the encrypted partition
cryptsetup luksClose /dev/mapper/comstar

# Open and mount again, etc…
cryptsetup luksOpen /dev/sdc1 comstar
mount /dev/mapper/comstar /media/comstar

/usr/bin/ld: crti.o: No such file

Wednesday, August 6th, 2008

Typical libc6-dev missing, example:

$ sudo invoke-rc.d varnish start
Starting HTTPd accelerator: /usr/bin/ld: crti.o: No such file: No such file or directory
collect2: ld returned 1 exit status
pclose=256
Internal error: GCC returned 0×0100
invoke-rc.d: initscript varnish, action “start” failed.

Solution:

$ sudo apt-get install libc6-dev

Specially you Mr. politician

Monday, August 4th, 2008

Read sudo msg once or twice a year:

“We trust you have received the usual lecture from the local System
Administrator. It usually boils down to these three things:

#1) Respect the privacy of others.
#2) Think before you type.
#3) With great power comes great responsibility.”

xmonad + GNOME

Sunday, June 8th, 2008


Finally I feel comfortable with my desktop.
I was using xmonad for a couple of months but I wasn’t liking with the ways I had to show a desktop bar, I was using dzen2 but with no time to put all the gadgets and things I need / like. So in the first free time I had I tried it with GNOME. Try it you too! it’s very easy to configure (with xmonad 0.7) Ah! one last important thing: if it doesn’t work at the first attemp, try to remove your .gnome and .gnome2 directories