Tags

academic (12) linux (9) latex (7) networking (5) server (5) internet (4) lyx (4) python (4) science (4) soa (4) ubuntu (4) django (3) virtualization (3) java (2) math (2) tip (2) backup (1) beamer (1) eclipse (1) phd (1) private (1) rest (1) web (1) wifi (1) windows (1)

Friday, October 15, 2010

Windows 2008 on KVM no disk solved (proxmox)

If you have problem finding it - windows 2008 does not play well with SCSI virtual disk in KVM. On the other hand, for VIRTIO you have to point Windows to additional driver iso with VIRTIO drivers. You can find them here.

Thanks to Proxmox VE support forum for help.

Thursday, September 30, 2010

Dymo LabelWriter 400 on ubuntu

Dymo LabelWriter 400

Today I bought Dymo LabelWriter 400 printer for labels. Surprisingly it works like a charm on my ubuntu machine. It gets recognised as normal printer, all you have to do is to download cups driver from Dymo page and compile it. (do not forget to apt-get install libcups2-dev and libcupsimage2-dev).

For a simple scenarios (nice word for lame label printing) I use http://www.glabels.org/, buy my ultimate aim is to create Django app to store information about various devices we own in our research group. The problem on out university is that we cannot easily get rid of old assets, as the procedures take time and are painful (as in plenty-papers-forms-filling painful). That is why one can find SCO server from the 80s, many types of handhelds (like 1337 Sharp Zaurus - you all remember the fuss) and even super size IBM supercomputer with computing power equal to Pentium 100 (literally).

Ok back to Dymo gadget. So my aim is to create and print labels from Django (Python) dynamically. And here I have a problem. I can see the paper size I use is "Large Address" 89x36mm size. When I try to print an image of that size (Gimp created) it results in taking only circa 2/3 of the label. I am still trying to figure out how it can be. Maybe image gets transformed into postscript and the size gets smaller ? Also surprisingly cups fit-to-page option does not work.

Anyway. I will try to do it and try to post the result.

Tuesday, September 28, 2010

Custom registration form with django-registration

Following StackOverflow question I manage to customise registration form used with djang-registration application.

The SOF answer not explanatory, so here it what you have to do:

1. Copy imports and register method from django-registration default backend (it is in __init__.py) and paste it in step 3.
2. Create your form, example below:

from registration.forms import RegistrationForm

...
class UserRegistrationForm(RegistrationForm):
        first_name = forms.CharField()
        last_name = forms.CharField()
3. Create a file in your APP HOME, in which you implement your own backend. I used regbackend.py, as in the example. Paste imports and register method from step 1, see code below:
from django.conf import settings
from django.contrib.sites.models import RequestSite
from django.contrib.sites.models import Site
from django.contrib.auth.models import User
from registration import signals
from PROJECT.APP.forms import UserRegistrationForm
from PROJECT.APP.models import *
from registration.models import RegistrationProfile
class MyBackend(object):

   def register(self, request, **kwargs):
        username, email, password = kwargs['username'],kwargs['email'], kwargs['password1']
        if Site._meta.installed:
            site = Site.objects.get_current()
        else:
            site = RequestSite(request)
        new_user = RegistrationProfile.objects.create_inactive_user(username, email,
                                                                    password, site)
        signals.user_registered.send(sender=self.__class__,
                                     user=new_user,
                                     request=request)
        user = User.objects.get(username=username)
        user.first_name=kwargs['first_name']
        user.last_name=kwargs['last_name']
        address_user = Address()
        address_user.save()
        contact_user = Contact(address=address_user,email=user.email)
        contact_user.save()

        address_company = Address()
        address_company.save()
        contact_company = Contact(address=address_company)
        contact_company.save()
        company = Company(contact=contact_company, admin=user)
        company.save()
        user_profile = UserProfile(user=user,contact=contact_user,position='',company=company  )
        user_profile.save()
        user.save()

        return new_user

4. Change your urls.py
import PROJECT.regbackend
from PROJECT.APP.forms import UserRegistrationForm
from registration.views import register
urlpatterns = patterns('',
...
url(r'^register/$', register, { 'backend': 'PROJECT.regbackend.MyBackend' }, name='registration_register'),
...
)


Here you go. Now you can add custom fields to the form. Also you can use form validators from django-registration. They are placed in forms.py in the sources.

Wednesday, September 22, 2010

Custom js and css in Django forms

Just to remind myself. If you want to put custom js or css when your form displays, you have to write your own widget. This is obvious. However docs do not say about one important thing.

You have to include {{forms.media}} tag in your template's head.

Tuesday, September 21, 2010

Django and i18n

Just a note post to remember how to set up the i18n in Django for the templates.
1. apt-get install gettext
2. Add {% load i18n %} to the top of the templates.
3. Add 'django.middleware.locale.LocaleMiddleware' to MIDDLEWARE_CLASSES
4. Add 'django.core.context_processors.i18n' to TEMPLATE_CONTEXT_PROCESSORS
5. Insert {% trans "VARIABLE_MSG" %} into your templates, where you need the translations.
6. mkdir locale
7. Run python manage.py makemessages -l LANG_CODE -a to generate po files
8. Run python manage.py compilemessages to compile po files into mo files.

That is it.

Friday, September 17, 2010

Simple animations with Beamer overlays

Sometimes you want to create a simple “animation” in beamer, for example to show step by step transitions in labelled transition system.

In PowerPoint style tool, you would just use the internal drawing capabilities. In Beamer it is not so easy. Fortunately Beamer has overlays, so you can just create many figures, each one representing the next frame in your animation. Without overlays, you would create Beamer frame for each of these picture frame. However this method is not code efficient and you just end with thousands of LaTeX lines. With overlays you can create one beamer frame and control the order in which components are shown.
Have a look at the example. Suppose, I want to show an animation of transitions in a labeled transition system. I created 4 pictures in Dia: step1.pdf, step2.pdf, step3.pdf and step4.pdf. I also want to show appropriate text on each animation frame. So what I have to do is to show step1.pdf only on frame 1, step2.pdf only on frame 2, etc. See the code.

begin{frame}{Steps example}
  \begin{figure}[H]
    \begin{center}
      % \only shows component only on frame X of the animation
      \only<1>{ \includegraphics[width=0.6\textwidth]{step1.pdf}}
      \only<2>{ \includegraphics[width=0.6\textwidth]{step2.pdf}}
      \only<3>{ \includegraphics[width=0.6\textwidth]{step3.pdf}}
      \only<4>{ \includegraphics[width=0.6\textwidth]{step4.pdf}}
    \end{center}
  \end{figure}
 
  \begin{block}{Labels for animation frames}
    \begin{itemize}
      % <1-> will show the text all frames from 1-X, <2-> on frames 2-X and so on
      \item<1-> step 1 is the first 
      \item<2-> then goes step 2
      \item<3-> and step 3
      \item<4-> finally the step 4
    \end{itemize}
  \end{block}
\end{frame}

Custom IMAP in Vim LaTeXSuite

Vim LaTeXSuite uses IMAPS to ease  LaTeX documents creation. For example you can write EFI in insert mode and you automatically get:
\begin{figure}[<+htpb+>]
  \begin{center}
    \includegraphics{<+file+>}
  \end{center}
  \caption{<+caption text+>}
  \label{fig:<+label+>}
\end{figure}<++>
You can navigate through the placeholders (<+somthing+>) with CTRL+J to fill them in. To create custom IMAP, you place it in ~/vim/ftplugin/tex/vim. Example for Beamer frame:
:call IMAP('BFR',"\\begin{frame}\\\frametitle{<++>}\<++>\\\end{frame}", 'tex')
The first argument "BFR" is a name for the IMAP, the second one is a body to place when vim sees BFR typed in. 'tex' word attaches the IMAP only to tex type files.