Skip to main content

Posts

Showing posts with the label hacks

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 workarounds... In CVS you can't rename a directory, you can't either remove a directory. Instead, 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 directories. 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

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, re...

Resizing images and generating animated gifs

After writing my last posts (P lotting 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 pan 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 .

ftdi232 permission on Ubuntu

I'am using the ftdi chip with bitbang mode to control some hardware with linux. Every time I copy my software to a new desktop, it always take me hours to figure out why it has no permission to run the bitbang mode as a regular user. Every website or forum I look around tells me about the udev, but I check back on the working desktops and there is no udev rule for the ftdi hardware. And after trying to force permissions with chgrp and chmod directly on /dev/bus/usb/* I figured out that I had to master at least a little about udev rules. Checking with a little more care at a working machine I´ve found a Virtualbox instalation which created a udev rule for the virtualbox usb driver. Changing that rule to be used with the FTI chip I do the following steps, with had worked perfeclty: Create the file /etc/udev/rules.d/10-ftdi.rules Write on it: SUBSYSTEM=="usb_device", GROUP="dialout", MODE="0664" SUBSYSTEM=="usb", ENV{DEVTYPE}=="u...

Mac OS X in Linux via VirtualBox (as guest OS)

That is some thing I want to do for quite some time: Install Mac OS X Snow Leopard as a guest OS in a VirtualBox Linux host http://martinml.com/en/how-to-install-mac-os-x-snow-leopard-in-virtualbox/ http://blog.nguyenvq.com/2010/12/04/mac-os-x-in-linux-via-virtualbox-as-guest-os/ http://myhack.sojugarden.com/guide/

Using ffmpeg to encode a high quality video

I had acquired some high quality images and was willing to encode them into a video, but ffmpeg default settings was always outputting a ugly video which had 1280x720, but with lots of artifacts. After googling a little, I've found: http://stackoverflow.com/questions/3561715/using-ffmpeg-to-encode-a-high-quality-video Digging a little more on the comments I've found: You need to specify the -vb option to increase the video bitrate, otherwise you get the default which produces smaller videos but with more artifacts. Try something like this: ffmpeg -r 25 -i %4d.png -vb 20M myvideo.mpg So, the key was the -vb flag! ffmpeg -i Image-%d.jpg -s 1280x720 -aspect 16:9 -r 24 -vb 20M teste.mp4

Getting which browser access your site, from apache's logs

I am developing a small web based system to run inside my sector here where I work. I had spend some time to make it compatible with the majority of web browsers available. I'm still not using html 5 and rendering dynamic graphics to png to display on Internet Explorer browsers. Even the PNG transparency is fixed to a solid background color for better rendering on Internet Explorer 6, so I decided to check which browser my colleges are using to access this small system. To do it so, I used the follow line on my server's console: cat /var/log/apache2/access.log | cut -d "\"" -f 6 | sort | uniq Which had returned: GbPlugin Mozilla/4.0 (compatible; MSIE 7.0 ; Windows NT 5.1; InfoPath.1; InfoPath.2) Mozilla/4.0 (compatible; MSIE 7.0 ; Windows NT 5.1; InfoPath.2) Mozilla/4.0 (compatible; MSIE 7.0 ; Windows NT 5.1; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; InfoPath.2) Mozilla/4.0 (compatible; MSIE 8.0 ; Windows NT 6.1; Trid...

Changing SVG with inkscape from command line

One can do more than simple convert vector to raster drawings with inkscape from the command line. In fact, there are other tools if the goal is just converting files, as rsvg and convert. With inkscape, is also possible to change the drawing, using verbs . From the inkscape man page , we can find the folowing example: Duplicate the object with id="path1555", rotate the duplicate 90 degrees, save SVG, and quit: inkscape filename.svg --select=path1555 --verb=EditDuplicate --verb=ObjectRotate90 --verb=FileSave --verb=FileClose Googling a little on inkscape "--verb" , I did find more examples , a list with the available verbs and details from the inkscape wiki .

How to fix Emacs 23 Huge ungly font on Lucid

Since I've upgraded to Ubuntu 10.04 (Lucid) Emacs 23 now has beautiful antialiased fonts, but I like the old bitmaped X11 "fixed" font. I do use a .Xresources file to setup emacs default font. This is my emacs section at .Xresources !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ! emacs, xemacs !emacs*Background: DarkSlateGray emacs*Background: Black !!!emacs*Foreground: Wheat emacs*Foreground: White emacs*pointerColor: Red emacs*cursorColor: Red emacs*bitmapIcon: on emacs*font: fixed !!!emacs*font: 9x15bold !!emacs*geometry: 100x40+20+20 But for my surprise using this setup emacs launches with a ugly huge serif font. I tried to launch emacs with -fn fixed but the ugly font did still there. So I checked at my /etc/X11/fonts/misc/xfonts-base.alias, which is the file where fixed font is declared. And it was there: fixed -misc-fixed-medium-r-semicondensed--13-120-75-75-c-60-iso8859-1 And which had called my attention, was that 6x13 font alias had the same properties as the fixed:...

Extended desktop at the login screen in ubuntu

I have an ATI Raden dual head at my desktop here at my job. I like to use WindowMaker as my window manager of choice, but since I had upgraded to Ubuntu 10.04 Lucid, WindowMaker is showing some issues regarding the dual monitor setup. WindowMaker follows the login screen (GDM) monitor setup and when I launch a gnome-session, things get messed up. The first solution which came to my mind is to make gdm aware of the two monitors. "Googling" around I've found two usefull links: https://help.ubuntu.com/community/MultiseatOneCard http://ubuntuforums.org/showthread.php?t=1611704 Following the first section of the first link ("Extended desktop through both monitors") I've wrote my new xorg.conf file: Section "Monitor" Identifier "monitor0" EndSection Section "Monitor" Identifier "monitor1" Option "RightOf" "monitor0" EndSection Section "Device" Identifier "card0...

uSleep on windows (win32)

I am facing a terrible issue regarding timing on windows. Googling arround, I've found those infos: Using QueryPerformanceCounter and QueryPerformanceFrequency APIs in Dev-C++ ( http://yeohhs.blogspot.com/2005/08/using -queryperformancecounter-and_13.html ) QueryPerformanceCounter() vs. GetTickCount() http://www.delphifaq.com/faq/delphi_windows_API/f345.shtml How to time a block of code http://www.cryer.co.uk/brian/delphi/howto_time_code.htm And Results of some quick research on timing in Win32 http://www.geisswerks.com/ryan/FAQS/timing.html With that I'm trying to write something like a uSleep function for windows: # include<windows.h> void uSleep ( int waitTime){ __int64 time1 = 0, time2 = 0, sysFreq = 0; QueryPerformanceCounter((LARGE_INTEGER *)&time1); QueryPerformanceFrequency((LARGE_INTEGER *)&freq); do { QueryPerformanceCounter((LARGE_INTEGER *)&time2); // }while((((time2-time1)*1.0)/sysFreq)<waitTime); } while ( (time2-time1) <waitTime); } T...

Low cost microcontrolling

I had a terrible issue at work today. We certainly have to give up from a windows controlled device, depending on time critical software to use a cheap and easy to find microcontroller. Making a couple of phone calls to local electronics shops, draws me to one single option. Microchip's PIC 16F family. So, let's go to PIC world: http://www.grennan.com/picprog/ (Programming the PIC16F84 with LINUX) The PIC16F84 is easily found at any electronics shops in my town. It costs around R$ 15,00 (fifteen reais), local brazilian currency, which is around US$ 8.45. Programming PIC’s in Linux using C with SDCC Intro to Programming PIC Microcontrollers in Linux http://www.lancos.com/prog.html (PonyProg - GLP Serial devices programmer) http://www.freenet.org.nz/sdcc/ (sdcc for PIC HowTo) There is a good Spanish site about PIC projects at http://www.micropic.es/

Some free/open tools for hobbies

[Open source PCB routing] MUCS-PCB - The University of Manchester School Of Computer Science PCB design software http://intranet.cs.man.ac.uk/apt/projects/tools/mucs-pcb/ Ladder Logic for PIC and AVR http://www.cq.cx/ladder.pl SketchFlat: 2d CAD, with Constraints http://www.cq.cx/sketchflat.pl SOLVESPACE -- parametric 3d CAD http://solvespace.com/index.pl And for autorouting on kicad , there is the closed source freerouting

wxTerm

IFTools has an free/libre open source (wxWindows license) communication terminal which uses a multi platform communications library. Worth to take a look at: https://iftools.com/opensource/download.en.php

Coffee machine robot

Here at IDEIA we share a common spare time project. We want to build a robot which brings the coffee from the kitchen to our offices. This project was a little inspired by the S.T.A.I.R. project from Stanford. Looking around we've found the Mobile Robot Programming Toolkit (MRPT) . And perhaps worth to look at: Arduino Ethernet Shield and Arduino Ethernet Library

Kicad - crossplatform suite of programs for EDA

Working in a place where people do projects on electronics using different platforms (windows and linux) certainly leads us to look for some tool which enables us to exchange our schematics and layouts through all this platforms. There is where Kicad came to help us. And, to help us to use it, here is a short tutorial on how to do simple things with Kicad: Tutorials for KiCad - A Free Open Source Schematic and PCB Layout Editor KiCad Overview and Schematic Tutoria l Going from Schematic to PCB Layout in KiCad (using Cvpcb) Making New Components and Modules (Footprints) in KiCad: Designing PCBs in Kicad and PcbNew: PS.: Other interesting link on GNU/Linux and Electronics: http://1010.co.uk/scrying_tech_notes.html And on electronics: http://www.electronics-lab.com/blog/?tag=power-supply&paged=2

Convert Scanned PDF Documents to Text without having to wait for google bots

Working supporting old scientific hardware sometimes brings me some challenges. Usually, the manuals are only on paper and when there is a digital version it was digitized (scanned) . Googling a little, came to me an article which relies on waiting for the google to index your files and OCR them. But there is an open source alternative. Looking a little further, I did find another two articles at linuxquestions.org and at linux.com , on which I've found the tesseract-ocr . So to solve my issue, I had to first convert my PDF file to a bunch of TIF images, and so OCR them with tesseract. This way: gs -dNOPAUSE -sDEVICE=tiffgray -r300x300 -sOutputFile=page%03d.tif -- 1850_operators_manual.pdf ls -1 *.tif | cut -d e -f 2 | while read line ; do tesseract "page"$line "page"$line -l eng; done Hope this helps somebody...