Sunday, January 14, 2018

Ray Marching and Signed Distance Functions

This is generated by intersecting rays with a signed distance function!
Here's an excellent explanation of how it works:

Here's a page from the creator of this model with more examples:

Wednesday, April 19, 2017

Stop TeXShop memory leak

Long TeXShop writing sessions (several weeks in my case) reveal that TeXShop leaks memory. I ended up with a 5Gb process without any open file!
This seems to be an old incomprehensible issue but it has a simple solution, just run the following line in your terminal

   defaults write TeXShop ReleaseDocumentClasses 0

If you want to check the status of the variable before changing it:

   defaults read TeXShop ReleaseDocumentClasses


Sunday, March 12, 2017

Fixing textext 0.4.4 in Inkscape 0.91 with OSX

textext is a great Inkscape extension that allows to incrustante LaTeX formulas in the drawings. However, it seems that textext was last updated in 2010 (v0.4.4) and since then some python calls to the md5 package have become deprecated.
This is obviously an issue for recent OS. 
Traceback (most recent call last):
  File "", line 210, in cb_ok
    self.callback(self.text, self.preamble_file, self.scale_factor)
  File "", line 369, in
    converter_cls, old_node))
  File "", line 387, in do_convert
    new_node = converter.convert(text, preamble_file, scale_factor)
  File "", line 879, in convert
    return PdfConverterBase.convert(self, *a, **kw)
  File "", line 750, in convert
    self.tex_to_pdf(latex_text, preamble_file)
  File "", line 727, in tex_to_pdf
    exec_command(['pdflatex', self.tmp('tex')] + latexOpts)
  File "", line 592, in exec_command
    raise RuntimeError("Command %s failed: %s" % (' '.join(cmd), e))
RuntimeError: Command pdflatex /var/folders/2y/h0000gn/T/tmpUcu75l/tmp.tex -interaction=nonstopmode -halt-on-error failed: [Errno 2] No such file or directory

Thursday, July 14, 2016

Error associating all .ply files to MeshLab in OSX El Capitan

When trying to associate MeshLab application to all the .ply files with the Always open with or Change All...  buttons I get the following error
An unexpected error occurred (error code -10813).
The operation could not be completed.

The problem is that MeshLab is missing the key CFBundleIdentifier in its Info.plist.
To solve the problem edit its plist file
> open /Applications/ 
and add the key CFBundleIdentifier with value com.vcg.MeshLab.

Then touch the application tell OS X about the change
> touch /Applications/
And retry associating the file type.

Monday, December 7, 2015

Hide Matlab Start Bar / Busy Bar / Status Bar

Reclaim precious screen space by disappearing the "Start bar" (in older versions of Matlab) whose main purpose is saying Busy.



Sunday, January 12, 2014

SMC reset. Random system freezes, and unresponsive keyboard & touchpad after plugging USB device

Lately I had some problems with my macbook air. Random system freezes, and unresponsive keyboard & touchpad after re-opening the lid.

I first tried a memory diagnostic (by booting pressing 'D') to discard a memory fault, but the RAM was OK. After surfing the web I found that I may have been needing to reset the SMC (System Management Controller). So I did, it but in the end the system continued to randomly freeze after plugging some USB devices.

Reset Macbook Air's SMC
  1. Shut down the computer 
  2. Plug in the power adapter if its not already connected.
  3. On the built-in keyboard, press the (left side) Shift-Control-Option keys and the power button at the same time.
  4. Release all the keys and the power button at the same time.
  5. Reboot as usual.
The procedure for other Mac's is slightly different, so it's better to look them up here or here.

Solution to unresponsive keyboard & touchpad after plugging USB device

In the end the culprit of this behavior was the android file transfer tool. What solved my issue was to disable the autostart of this application.

    Saturday, June 15, 2013

    Useful processes to kill in OSX

    From time to time, some of user interface or system process go crazy or freeze. It's always good to know how to kill and restart those processes them without restarting the system.

    • Frozen Finder: Kill it. Restarts by itself
      > sudo killall Finder
    • Frozen Spotlight: Kill it. Restarts by itself
      > sudo killall SystemUIServer
    • mDNSResponder sometimes gets stuck (observed in 10.5 and 10.6) and as it does so the system-wide name resolving stops working. Meaning that internet names are not resolved anymore
      > sudo launchctl unload /System/Library/LaunchDaemons/
      > sudo launchctl load /System/Library/LaunchDaemons/
      or ometimes it also works to kill it and restarts by itself
      > sudo killall mDNSResponder
    • If mds goes crazy indexing some new volume: Stop it:
      > sudo mdutil -i off /path_to_volume
      or stop it on all volumes with:
      > sudo mdutil -a -i off
    • ... any other?


    OSX: Start SSH socks proxy and change network settings from the command line

    Everybody loves to travel. I also enjoy to experience the internet from other places, but this I can do without leaving my house. All I need is a remote unix computer which I can access by SSH.

    The script below sets up SSH dynamic port forwarding and changes the network proxy settings all by itself. When communication is cut, with Ctrl-D, it goes back to the usual proxy configuration (no proxy). Tested on OSX 10.6.8.

    #description     :initiates SSH dynamic port forwarding and sets up 
    #                 the network proxy settings for you
    #author          :Gabriele Facciolo (
    #date            :20130615
    #version         :1.0
    #OSX version     :Tested on OSX 10.6.8  
    #usage  [remoteHost [localPort (default:1080)]]
    if [ "${1}" != "" ]
    if [ "${2}" != "" ]
    if [ "${SSHHOST}" == "" ]
       echo "${0}: initiates SSH dynamic port forwarding and "
       echo "sets up the network proxy settings for you."
       echo ""
       echo "    Usage:   ${0} [remoteHost [localPort(default:1080)]]"
       echo ""
       echo "Indicate a remoteHost, or set the DEFAULTSSHHOST variable" 
       exit 1
    networksetup -listallnetworkservices | grep -v asterisk | while read line ; do 
    t=`networksetup -getinfo "$line" | grep "IP address" | grep -v none`
    if [ "$t" ]; then
       tt=`networksetup -getsocksfirewallproxy "$line" | grep -v Authenticated | grep "Enabled: No"` 
       if [ "$tt" ]; then
          echo Enabling SOCKS on $line
          networksetup -setsocksfirewallproxy "$line" localhost $LOCALSOCKSPORT
    echo ""
    echo "========================================================="
    echo "========================================================="
    echo ""
    networksetup -listallnetworkservices | grep -v asterisk | while read line ; do 
    t=`networksetup -getinfo "$line" | grep "IP address" | grep -v none`
    if [ "$t" ]; then
       tt=`networksetup -getsocksfirewallproxy "$line" | grep -v Authenticated | grep "Enabled: Yes"` 
       if [ "$tt" ]; then
          echo Disabling SOCKS on $line
          networksetup -setsocksfirewallproxystate "$line" off

    Description of the key commands:
    • networksetup -listallnetworkservices
      Displays a list of all the network services on the server's hardware ports. An asterisk (*) denotes that a network service is disabled.
      Sample output:
               USB Ethernet
               Bluetooth DUN
    • networksetup -getinfo "Airport"
      Displays the IP address, subnet mask, router, and hardware address for the device that you specify.
    • networksetup -getsocksfirewallproxy Airport
      Displays SOCKS proxy (server, port, enabled value) info for the device.
      Sample output:
               Enabled: No
               Server: localhost
               Port: 1080
               Authenticated Proxy Enabled: 0
    • networksetup -setsocksfirewallproxy Airport localhost 1080
      Set and enable the SOCKS proxy server  localhost:1080.
    •  ssh -C -D *:1080
      Launch ssh with dynamic port forwarding
    • networksetup -setsocksfirewallproxystate Airport off
      Disables SOCKS proxy.


    Saturday, January 26, 2013

    Single TAB bash completion

    Bash completion (when enabled) allows you to complete paths, commands, and filenames by hitting the TAB key. On the first press of the TAB key it completes the command as long as there is no ambiguity about the completion. If there are several possible completions a second key press reveals all the options.

    It is possible to setup bash/readline to reveal the options after the first key press. Just add the following line to your ~/.inputrc :
     set show-all-if-ambiguous on


    Sunday, October 14, 2012

    Download/backup BibTeX library from CiteULike, including all the attached PDF

    CiteULike is a convenient solution for bibliographic management, but sometimes an off-line replica of the bibliography is also needed. This can be achieved by exporting the CiteULike library in BibTeX format, furthermore BibDesk (and probably other managers too) can be synchronized directly with the CiteULike server.

    While it is easy to export a .bib file from CiteULike, downloading all the attached files and having the .bib linking to the downloaded files is a different story.

    BibTeX and JSON exports of the CiteULike library can be retrieved from:
    The BibTeX export can be read directly into a bibliographic manager, but the JSON export contains more information than the .bib, in particular it contains the location of the attached PDFs. So the idea of the Python script linked below is to do the following
    1. download the CiteULike library in BibTeX and JSON formats
    2. parse the JSON export and download all the attachments
    3. modify the .bib file to include links to the downloaded copies of the attachments
    the links in the .bib file should work for BibDesk and JabRef.

    Before running the script:
    • setup CITEULIKE_USERNAME and CITEULIKE_PASSWORD variables in the script
    • verify you have wget and pybtex installed
    Download the Python script:

    Gory details from
    # save session cookies
    > wget -O /dev/null --keep-session-cookies  --save-cookies cookies.txt --post-data="username=xxxx&password=yyyy&perm=1"
    # download bibtex with private comments and download an attachment
    > wget -O export.bib --load-cookies cookies.txt
    > wget --load-cookies cookies.txt

    Friday, September 14, 2012

    Writing floating point multi-channel TIFFs in Matlab

    In a previous post I've commented on how to read a multi-channel floating point TIFF in Matlab using the Tiff class (available since R2009b).
    The Tiff class also permits to write all TIFF flavors. But since this TIFF format is so flexible, setting up everything for writing a file is not straightforward. Concretely I'm interested in writing a multi-channel floating point TIFF. Using the details found here, I've wrote this functions that wraps all the parameter setup for writing this type of TIFF files.
    function writeTIFF(data, filename)
    % writeTIFF(data, filename)
    % writes data as a multi-channel TIFF with single prec. float pixels
       t = Tiff(filename, 'w');
       tagstruct.ImageLength = size(data, 1);
       tagstruct.ImageWidth = size(data, 2);
       tagstruct.Compression = Tiff.Compression.None;
       %tagstruct.Compression = Tiff.Compression.LZW;        % compressed
       tagstruct.SampleFormat = Tiff.SampleFormat.IEEEFP;
       tagstruct.Photometric = Tiff.Photometric.MinIsBlack;
       tagstruct.BitsPerSample =  32;                        % float data
       tagstruct.SamplesPerPixel = size(data,3);
       tagstruct.PlanarConfiguration = Tiff.PlanarConfiguration.Chunky;

    Saturday, August 25, 2012

    Change text inside multiple files (command line)

    I always forget these commands, and they are so useful.
    The sed command to replace some text in a set of files:
         sed -e 's/old text/new text/g'  -i .trash  *.c 

    The regular expression 's/some text/new text/g' is applied to each line of each file *.c.
    And the -i flag saves a backup of each file.

    The regular expression language is powerful, for instance allows to remember parts of the pattern in the substitution. An example: the following command puts quotation marks around everything that follows the first = sign in each line of
      sed -e 's/=\(.*\)/="\1"/'

    The pattern enclosed between \(   and   \) is stored in \1, and then used in the replaced text.


    otool: shows the shared libraries of a file (like ldd)

    In OSX, the command to show the shared libraries that a binary uses is:
       /usr/bin/otool -L  binary_file

    In Linux and Solaris the equivalent command is ldd, and I am used to it,
    so I have this alias in my ~/.bash_profile  file:
       alias ldd="/usr/bin/otool -L "

    Thursday, August 16, 2012

    Homebrew package manager for OSX + Tips

    Forget Fink and MacPorts, Homebrew is the miracle package manager you are looking for.

    Homebrew installs packages to their own directory and then symlinks their files into /usr/local.
    Then there is no need to tweak the system's and compiler's search paths to reach the packages. Also the installation is extremely simple, and the syntax familiar:
      brew [search, install, remove] packagename

    The big critic I read about was the lack of packages. Never noticed, probably because the number of packages have exploded during the last year. The packages are built locally, so compiling large applications may take considerable time.

    • Compile for multiple architectures. If, for some reason, you need to compile a program/library with multiple architecture support, like on a 64bits system but with 32bits legacy applications. Then, while installing use the --universal flag:
           brew install --universal -v libtiff
      it will compile a "fat" library with multiple architectures (env UNIVERSAL_ARCH="i386 x86_64" to specify which architectures).
    • Python. This setting is very important, but may depend on the version of OSX.
      When I installed Homebrew it did not compile its own python, instead it used the python that came with the system. Then all python packages installed with Homebrew are stored in: /usr/local/lib/python2.6/site-packages,  which is not in the search path for  python. It must be specified with the environment variable PYTHONPATH, by adding this line to ~/.bash_profile :
        export PYTHONPATH=/usr/local/lib/python2.6/site-packages:$PYTHONPATH

      More on Python and Homebrew.
    • Big projects like GIMP, Inkscape, Firefox,  and many others...  Are not available as packages, they are already distributed as standalone OSX applications.

    Wednesday, August 15, 2012

    Two-finger scrolling in Windows laptops (also Linux)

    Two-finger scrolling and two-finger tapping (right click) are the two multi-finger gestures that I use the most in Mac. I'm so habituated to them that when I use a Windows laptop becomes a frustrating experience: always reaching for the right button or the scroll area of the pad.

    Turns out that Synaptics TouchPads allow multi-finger gestures, and it is just a matter of drivers to enable them (just to be clear, almost all TouchPads out there are Synaptics).
    Even better, without manipulating the driver. Two-Finger-Scroll is a small application that allows to enable two and three finger gestures on the Synaptics TouchPads, and it works just fine.


    Update: multi-finger gestures also available for Linux!!  In Ubuntu/Debian just install the gpointing-device-settings package, or anything that says Synaptics.

    Friday, August 10, 2012

    Record audio from the system output

    soundrec.exeBy default in OSX it is not possible to record audio from the system output. This occurs if you try to record sound from an application, like a web browser.
    Moreover, besides GarageBand there is no integrated lightweight sound recorder in OSX (like the old and reliable soundrec.exe).

    The solution to the first problem is provided by an Audio Routing device/application.
    Soundflower is popular open source extension that allows applications to pass audio to other applications. This article explains how to use it.
    Jack is another free option but apparently has more features and is more complicated to use. Other popular non-free options are WireTap and Rogue Amoeba.

    As for recording under OSX, Audacity is a free and "lightweight" (80Mb) application that works.


    Wednesday, August 8, 2012

    Find broken symbolic links

    To list the symbolic links along with where they point to:

         find -L /PATH/TO/SEARCH -type l -exec ls -l {} \;  

    Omitting  -exec ls -l {} \;  will just list the link name.

    Other references:

    Friday, May 18, 2012

    Convert PDF presentations to Keynote

    PDF to Keynote is a free tool for converting PDF-based presentations (e.g., made using LaTeX with Beamer) into Apple's Keynote format. Once translated into Keynote format, every page of the original PDF becomes an image on its own slide, so no further edition is possible.
    The advantages of presenting PDFs using Keynote include: the presenter display, rehearsal support, and notes visible only to the presenter.


    Sunday, May 13, 2012

    Read floating point multi-channel TIFFs in Matlab >=R2009b

    For reading a TIFF image in Matlab usually the imread function suffices:

    d1 = imread('myfile.tif'); 

    This call will even load single channel f32 (32bit floating point) images. But for multi-channel f32 images will fail. This is not a surprise, since most of the applications don't even load the single channel f32 files.

    Starting from version R2009b Matlab includes a new Tiff class that implements much more of the TIFF format, allowing to read and write many flavors of TIFF files. The call is slightly different from imread: 

    t = Tiff('myfile.tif'); 
    d2 =;