Thursday, July 28, 2011

How to convert videos to be imported in iMovie for free

Hi,

these days I'm preparing a funny video to be shown at the wedding party of one of my best friends. For that, I asked all our friends to send me short clips of greetings or jokes.

But then I received clips in whatever format...and iMovie does not accept many formats actually... :-(

So I started to google to find free tools to get them converted in Quicktime .mov easily.

After many trials I ended up with this list:

- mpg (muxed) --> mov : "ffmpegx"

- AVI --> mov : "ffmpegx"

- wmv --> mov : "HandBrake"

Monday, March 14, 2011

Regular expressions in Eclipse: some working examples

I found very useful the Regular Expressions support in the "Find and Replace" window of the Eclipse IDE.

Here some expressions I used. Mainly a reminder for me, of course; but I think they can be useful for others as well, as working examples.

Note that you can refer to groups within the regular expression in the "Search" field, with the symbol $ followed by an increasing number: $1 for the first group defined in the regular expression, $2 for the second and so on...

---

From: qDebug() << "Hello" << world.name() << "t_int32" << "!";
To: ERS_DEBUG(2, "Hello" << world.name() << "t_int32" << "!");

Search: (qDebug[(][)])(\s*[<]+\s*)(.*)([;])
Replace: ERS_DEBUG(2, $3);

---

Wednesday, September 15, 2010

Using CherryPy in Google App Engine applications

There are two articles telling about using CherryPy in GAE applications

http://boodebr.org/main/python/cherrypy-under-google-appserver

http://blog.dispatched.ch/2010/08/13/serving-images-dynamically-with-cherrypy-on-google-appengine/

I found them useful, but in none of them it's described how to install CherryPy for this use.

The problem with CherryPy in GAE it's that the Google framework does not host CherryPy, and it has to be shipped together with the application.

I just found the way:

1) Download CherryPy from the site www.cherrypy.org
2) Run python2.5 setup.py install --root
3) Go to and run cp -r Users//Library/Python/2.5/site-packages/cherrypy .

Now you can delete the folders System Users lib created by the installation command, and you can use cherrypy in your application!

Saturday, August 7, 2010

no more sound after a mac os x restart? Fixed

Ufff.... that what happened to me just some minutes ago: after a restart of my MacBook white, due to an overload (the system started to respond very slow, I had too many apps opened and it was many days I didn't shut it down)..... I had no more soud!!!
Remembering the old days, when I was used to spend hours in fixing Windows problems with drivers, corrupted updates and so on..... I was already prepared to do it...
But actually it was very easy fix!! And it was not due to Mac Os X itself, but to Soundflower application which I have installed on my system!!
Eh eh!! Mac...the more I discover you, the more and more I love you!! :-P

Problem:
No more audio after a restart of Mac Os X 10.6 Snow Leopard (mine is 10.6.4 version)

Solution:
If you have Soundflower installed, that may be the cause.

Soundflower is a software to redirect the output sound from the system or from an application to another application, where it's used as input source. It's a very nice piece of software indeed!
Usually I keep it off, but for some unknown (to me) reasons, after that restart the sound output
was not set anymore to the "Internal Speakers" (as the normal default), but to "Soundflower 2Ch". Changing back to "Internal Speakers" fixed the problem!! :-)
To check and fix it:

Go to "System Preferences" (from the Dock, or from the Apple Icon menu on the top bar), then go to "Sound", then go to the "output" tab; there you can see the option "Select a device for sound output" where, if you have Soundflower installed,you can select between:
Internal Speakers
Soundflower (2ch)
Soundflower (16ch)

In my case, after the restart, the output was strangely set to "Soundflower (2ch)", and setting back to"insternal Speakers" fixed the problem.

Have a nice summer day! :-)

Tuesday, May 4, 2010

Using Kerberos on Mac Os X 10.6 Snow Leopard

Problem:
I tried to use Kerberos authentication system out-of-the-box with my new Mac, and when I try to get a ticket I got this error:


$> kinit user@HOST.COM
$> kinit: Unable to acquire credentials for 'user@HOST.COM': Cannot resolve network address for KDC in realm HOST.COM

Solution:
So I googled a bit and I tried some recipes, but I just discovered that the order with configuration files are read by Kerberos changes sometimes. So instead of the conf file inside
~/Library/Preferences/edu.mit.Kerberos
I had to copy the same file to
/etc/krb5.conf

So create those two files with a content like this:


[realms]

HOST.COM = {
default_domain = host.com
kpasswd_server = afskrb5m.host.com
admin_server = afskrb5m.host.com
kdc = afsdb1.host.com
kdc = afsdb2.host.com
kdc = afsdb3.host.com
}

[domain_realm]
.host.com = HOST.COM



And you are done!
Then you can try using kinit to get a ticket like:


$> kinit user@HOST.COM Please enter the password for user@HOST.COM:

$> klist
Kerberos 5 ticket cache: 'API:Initial default ccache'
Default principal: user@HOST.COM
Valid Starting Expires Service Principal
05/04/10 15:28:11 05/05/10 01:28:11 krbtgt/HOST.COM@HOST.COM
$>


Note!
If you are looking information on how to access the CERN AFS from Mac Os X, you can find the settings for CERN here:
http://linux.web.cern.ch/linux/docs/kerberos-access.shtml

You can also look at this nice twiki about AFS at CERN with Mac Os X. But remember to edit the right config file in the right folder, otherwise Kerberos will complain.
https://e5wiki.physik.tu-dortmund.de/bin/view/Main/MacOSXCernKerberos

Monday, May 3, 2010

How to change or clear your Subversion password used by eclipse plugins on Mac OS X

I assume that you are using Eclipse Galileo on Mac Os X Snow Leopard, with JavaHL SVN client.

It happened to me that once I updated the password of my account on the subversion server machine, Eclipse did not allow me to connect to the repository anymore; moreover it did not ask me for a new password, I merely got errors like "The folder does not exists on remote server" and authentication errors on the Eclipse SVN Console.

After googleing for a while, I did not find the solution yet, and so I started to play around. Finally I solved the problem and I post the solution here; I hope it can save you some time :-)

You have to open the "Keychain" application from "Applications" --> "Utilities" --> "Keychain"

There you will find an "application password" related to SVN: mine contains something like "https://svn.host.com/". You double click on it and you change your stored password with the new one.

Now if you close Eclipse and then you open it again, it will notice that the SVN password was changed and when you will try to access the repository again, Eclipse will ask you the username/password couple again. You can type the new password again, and you can "save" it if you want. The new password is set.

Hope that helped! :-)

LaTeX: how to include a minted pygmentized piece of code in a figure environment, with three minipage in a row

Sometime we want to put two, three or more LaTeX objects side by side on one row. For example we want to put more figures one next to the other. Or we want to build complex figures gathering under one "figure" environment more objects like formatted text, images and highlighted source code using pygmentize and minted. Here below you will find a working example.
The same example is valid if we want to put fancy texts side by side like inside boxes, because the \fbox command does not allow to use complex-formatted text inside.

Here what you get




and here below the code to generate it.

ATTENTION!!!! Pay attenion to not insert empty lines in the source code between minipages!! Otherwise you will get the minipage environment put in a vertical column: because the empty lines will be evaluated as "new line" breaks. I say it here because I waisted some hours looking for this "bug"!!! ;-D :-P



\begin{figure}[h]
\centering
\begin{tabular}{c}
\begin{minipage}[c]{.40\linewidth}
\centering
\epsfig{file=ImagePlaceholder, scale = 2.0}
\end{minipage}
\begin{minipage}[c]{.10\linewidth}
\centering
\epsfig{file=RightArrow_Grey, scale=0.6}
\end{minipage}
\begin{minipage}[c]{.45\linewidth}
\begin{minted}[bgcolor=bg, fontsize=\tiny ]{python}
'3j0lep':{
'selectionCuts': {
'electron':{'deltaR_ej': 0.25}
}

'cuts': { 1: { 'label': 'Cut1',
'value': [20*Units.GeV]},
2: { 'label': 'Cut2',
'value': [100*Units.GeV,
40*Units.GeV,
40*Units.GeV],
},
3: { 'label': 'Cut3',
'value': 80*Units.GeV, },
},
}
\end{minted}
\end{minipage} \\
\\ %empty line for some space
\footnotesize
From requirements...
\hfill
...to the code!\\
\end{tabular}
\caption{Main caption.}
\label{MainILabel}
\end{figure}

Thursday, April 2, 2009

Linux: How to use an external hard disk, how to mount it

Problem: In my case I plugged the external hard disk into the USB port; a new folder with the name of my external HD was created, but it was empty.

Solution: I had to mount by hand the external hard disk, even if it was automaticaly recognized and a folder for it (empty) was created.

----------

The problem was that, when I plugged my external HD to the USB port of my Linux box, the disk was recognized and a folder was created under /media/NewHD , but the folder was empty. NewHD is the label, the name, that I choose when I first formatted my new USB external disk.

To solve I followed these steps:

  1. You have to find the "dev" name of your external HD after you plugged it in:
    dmseg
    You will find something like these lines:

    Initializing USB Mass Storage driver...
    scsi6 : SCSI emulation for USB Mass Storage devices
    Vendor: SAMSUNG Model: HM251JI Rev:
    Type: Direct-Access ANSI SCSI revision: 02
    SCSI device sdc: 488397168 512-byte hdwr sectors (250059 MB)
    sdc: assuming drive cache: write through
    SCSI device sdc: 488397168 512-byte hdwr sectors (250059 MB)
    sdc: assuming drive cache: write through
    sdc: sdc1

    From the last line you know that your external drive was mapped by Linux to the /dev/sdc1

  2. You have to check if the external drive was actually mounted somewhere else:
    mount
    You get something like this:

    [root@hece02] /media $ mount
    /dev/mapper/VolGroup00-LogVol00_Root on / type ext3 (rw)
    none on /proc type proc (rw)
    none on /sys type sysfs (rw)
    none on /dev/pts type devpts (rw,gid=5,mode=620)
    usbfs on /proc/bus/usb type usbfs (rw)
    /dev/sda1 on /boot type ext3 (rw)
    none on /dev/shm type tmpfs (rw)
    /dev/mapper/VolGroup00-LogVol01_Home on /home type ext3 (rw)
    /dev/mapper/VolGroup00-LogVol02_Scratch on /localscratch type ext3 (rw)
    none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
    sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)
    AFS on /afs type afs (rw)

    If your /dev/sdc1 is present there, you know that you can access the content of your drive from the path associated with the /dev/sdc1. Otherwise keep following.

  3. You have to mount the external hard disk:
    mount /dev/sdc1 /media/NewHD

  4. And now you can access the content of your disk! :-)

When you have finished, you have to unmount it, before unplugging it from your Linux computer; something like the "Safely Removing" in Windows.
Just type:
umount /media/NewHD
then you can unplug it.

Python: Exception TypeError "argument of type 'instance' is not iterable" in 'garbage collection' ignored. Fatal Python error: unexpected exception

Problem: I got a nasty Fatal error message running my Python code: "Exception exceptions.TypeError: "argument of type 'instance' is not iterable" in 'garbage collection' ignored"

Solution: I forgot to use vars() function when checking the existance of a variable in an imported module

-----------------

I got this error in my Python code today, and it took me 20 minutes to understand where the bug was.

Actually the line number showed in the error message was false. The error itself started some lines above and it propagated until the incriminated line.

So this was the error:


Exception exceptions.TypeError: "argument of type 'instance' is not iterable" in 'garbage collection' ignored
Fatal Python error: unexpected exception during garbage collection
Aborted


And the problem was an "IF" statement where I checked for a variable name in an imported module:

My "IF" was this:


if 'fileName' in myModule:
fileName = 'OutputFile_%s.py' % myModule.fileName


To fix the problem I had to correctly add "vars()", of course ;-)


if 'fileName' in vars(myModule):
fileName = 'OutputFile_%s.py' % myModule.fileName


The bug was very stupid, just forgot the "vars()" function. But it was not so easy to find because the error message Python gave was not so helpful.

Wednesday, April 1, 2009

Eclipse IDE: How to install and configure MinGW GNU C++ compiler for Windows

Eclipse IDE has the very nice CDT environment for C++ programming.

In order to use it under Windows, you have to install a C++ compiler.

Our suggestion is to install the MinGW compiler, "A MINimalistic Gnu for Windows" Gcc compiler.

Go to http://www.mingw.org/ and download the installer for Windows from here.

Then start the Installer and choose to install the basic package + the g77 compiler + Make for MinGW, as those are the tools needed for compiling C++ code with Eclipse... and not only with Eclipse ;-)

Once installed everything you have to add the MinGW path to your PATH environment variable, to make the compiler findable.

Let's say we have installed the MinGW package on C:\MinGW. Refer to the picture below.
You have to open Start --> Control Panel --> System. In the pop up window that appears select on the left side "Advanced System Settings" and then goes to the tab Advanced and choose "Environment Variables...". There look for the "Path" variable in the System Variables window below (look for PATH, instead, if you want to set the MinGW compiler only for you as user) and click on "Edit...". In the pop up window you'll find a long string to edit. Go to the end of that string line and add ";C:\MinGW\bin". Then "Ok" and again "Ok".





Now your new nice MinGW compiler is ready to be used.

To make a test open a new command prompt (Start --> All Programs --> Accessories --> Command Prompt) and try to type "mingw32-make --version". If everything worked fine you should see a window telling you the version of the newly installed package.

Now open your Eclipse IDE with CDT for C++. Eclipse now should see and should be able to use MinGW C++ compiler!! :-)

So...have fun programming C++! :-)