Tuesday, August 2, 2016

How much space emacs backup files are using...?

Everytime I use emacs, it automatically saves a backup file which filename ends with "~".
From time to time, I issue a recursive find command to wipe out  (delete) every emacs backup file from my home folder.
find . -iname \*~ -exec rm -rfv {} \;
And everything is clean.

I do it strictly to clean things up... not for any disk space concern...  But I was wondering how much disk space those backup files are consuming...

So, instead of an rm command, I had executed a df and piped all to awk to summarize...
find . -iname \*~  -exec du -s {} \; | cut -f 1 | awk '{s+=$1} END {print s}'

This time all the emacs backup files were comsuming only 1.6M, which isn't big deal... but I think it is better to get rid of them.

Wednesday, September 2, 2015

Extracting embedded images from SVG

With inkscape one can open and edit PDF files. But when the PDF comes with embedded images, the resulting SVG keeps the images as an embedded base64 encoded data. I wanted to extract those embedded images from the resulting SVG. But I didn't want to use the "export bitmap" option on Inkscape to extract those images, as whiting this way I wouldn't really know the original resolution besides the fact that Inkscape would re-encode the image data. So I wrote this one line to extract all images from one SVG.

i=1; grep data:image test.svg  | cut -d "," -f 2 | cut -d \" -f 1 |while read line ; do echo $line | base64 --decode >  $i.png ; i=$((i+1)); done 

Friday, July 31, 2015

Now, the kid's time

After my little experiment wit clay stop motion animation (link), I brought the camera home and showed the process to my kids... My older son wanted to give it a try... And here is his first movie.

Wednesday, July 29, 2015

Clay stop motion

A colleague from just the neighbor lab found an old webcam, which has no support (driver) for his Windows 7... He asked me to try to find an Windows 7 driver, or some driver which make the cam work for him... As I use a Linux workstation, I've just plugged the camera on an USB port to see what do I get. The camera worked pretty nicely...So we've lauched "Cheese" and grab some pictures of some clay that was laying around... It took less than 5 minutes to make this small animation...

After that, he forgot the windows driver and he lent that camera to me to play with the kids.

Friday, August 1, 2014

Emptying an entire CVS directory tree

Another one on CVS.
Keeping old projects in which one would spend so much effort to do a full migration to another version control system than just learn to live with the CVS limitations makes you find some weird workarrounds...
In CVS you can't rename a directory, you can't either remove a directory. In stead you can remove all files in the directory tree you want to remove, and do a "CVS update -P" pruning empty directories.
So, how to easily empty an entire directory tree? The find has a "-not" operator which lets you make an inverse logic. For example, you can find -name CVS to locate the CVS control directories and find -not -name CVS to find files other than the CVS control direcoties.
Finally, to empty an entire directory, but not touching the CVS control files and folders, one could run the following line:
find . -not -name CVS -a -not -name Entries -a -not -name Root -a -not -name Repository -not -type d | xargs rm; cvs remove

Tuesday, September 17, 2013

Arduino without arduino IDE

It has been a long time since my last post about hardware or embeded software...
This one is just about a link to:

A Brief Tutorial on Programming the ATMega (Arduino) without Arduino Software


The part which had call my attention most was the lesson 11, on persistence storage using the EEPROM.
There are much more, it worst a careful the reading.

Tuesday, June 4, 2013

Adding multiple files to CVS

Since the beginning, this blog was meant more as short mental notes for future retrieval. So, here comes another one:

I am a long term CVS users. I have lots of old projects which still being maintained with CVS for version control, backup and central repository. Most of these projects must be updated and/or must have new features added to them, some times I have to add lots of files to the repository, and doing this from the command line would be very painful if there were not powerful command line tools such as "find", "grep", "cut" and "xargs".

First, I have to add everything which is not a CVS control folder to the repository:

find . -not -name CVS -not -name Root -not -name Entries -not -name Repository -exec cvs add {} \;

Second, the remaning files from the projects root folder must be added to. Issuing a "cvs update", the appear with a question mark (?), but cvs echos a lot more info to the stderr. We can cut that off, rederecting the stderr to NULL, and grepping the question marks, cutting the second field and piping it to xargs to add those files to the cvs repository:
cvs update -R -P -d 2> /dev/null | grep "?" | cut -d " " -f 2 | xargs cvs add

Fine. Everything new is in the cvs repository.

Wednesday, November 23, 2011

Resizing images and generating animated gifs

After writing my last posts (Plotting memory usage on console and More trickery with gnuplot dumb terminal), I had to put here some lines used to make the screenshot I'd put there.
To resize all screen shot frames:

ls -1 *.png | cut -d . -f 1 | while read line ; do convert $line.png -resize 60% $line.mini.png; done

In stead of resizing the image, they can be cropped:
ls -1 *.png | cut -d . -f 1 | while read line ; do convert $line.png -crop 400x270+92+37 $line.mini.png; done

To make the animated gif
convert -delay 100 -loop 0 screenshot0*mini.png screenshot.gif

More trickery with gnuplot dumb terminal

In my post "Plotting memory usage on console" the chart doesn't panned the data.
Now, using a named pipe, the effect got a little bit nicer.
First we have to run the memUsage.sh script to get a file filled with memory usage info:
./memUsage.sh > memUsage.dat &
Then we have to create a named pipe:
mkfifo pipe
Now we have to run another process to tail only the last 64 lines from the memUsage.dat
while [ 1 ]; do tail -64 memUsage.dat> pipe; done &
And now we just have to plot the data from the pipe:
watch -n 1 'gnuplot -e "set terminal dumb;p \"pipe\" with lines"'
And that is it!

Plotting memory usage on console

This is just a simple hack to play around with gnuplot set to dumb terminal (character console), doesn't meant to be serious application.
First I had written a bash scritp to log memory usage a while ago:

So, while running this script in background (./memUsage.sh > memUsage.dat &), logging the data, the memory usage information can be plotted with gnuplot and watched in real time:
watch -n 1 'gnuplot -e "set terminal dumb;p \"memUsage.dat\" with impulses"'

The chart can be plotted with lines, with impulses or any gnuplot style option.