Showing posts with label Linux. Show all posts
Showing posts with label Linux. Show all posts

Friday, October 11, 2013

How to enable font subpixel smoothing in gnome-shell (Fedora 18)

The default desktop for Fedora 18, gnome-shell, does not offer an intuitive way to enable font sub-pixel smoothing for LCD monitor. Gnome 2 desktop had Fonts configuration utility for ages, but with gnome-shell, this useful capability is well-hidden.
  • Enable RPM Fusion repository. Click on RPM Fusion free for Fedora 18 link to install repository's configuration on your machine.

  • Install freetype-freeworld fronts package:
     
    $ sudo yum -y install freetype-freeworld
    
    

  • If doesn't exist, create $HOME/.Xresources file and turn subpixel rendering on:
     
    Xft.lcdfilter:  lcddefault
    
    

  • Start gnome-tweak-tool utility and configure:
    • "Font Hinting" to "None"
    • "Font Antialiasing" to "Rgba"



  • Reboot your machine.



  • Login back and validate the settings:
    $ xrdb -query
    
    Xft.antialias: 1
    Xft.dpi: 96
    Xft.hinting: 0
    Xft.hintstyle: hintnone
    Xft.lcdfilter: lcddefault
    Xft.rgba: rgb
    
    

  • You might also upgrade your version of liberation-fonts from Koji build for FC18. They are a good replacement for msttcorefonts.

    If all went as suggested, you should enjoy better-looking desktop.

    In conclusion, I might add that it is a crying shame for gnome-shell developers to destroy well-established Gnome desktop ecosystem in their relentless pursuit of the tablet market at the expense of poor Linux desktop users.

    Wednesday, June 27, 2012

    Howto change Desktop fonts

    Out of the box both GNOME and KDE applications are configured with the default Desktop Fonts of something like Sans 10 which looks ridiculously tiny and small on a 1440x900 LCD panel.
    Here is how to fix it:

    GNOME
    • Start GNOME Configuration Editor with Applications > System Tools > Configuration Editor
    • Drill down to desktop > gnome > interface
    • Change font_name attribute to Sans 14.
    • Set monospace_font_name attribute to Monospace 14.

    KDE
    • Start KDE Control Center with kcontrol.
    • Go to Appearance & Themes > Fonts category.
    • Set Desktop fonts to Sans 14.

    Saturday, June 23, 2012

    How to test for an empty env var in a shell script

    Recently, I came across one of my own bash scripts that goes way back. It relies on an environment variable being set, and if not, the script exits without a warning. I learned that the most elegant way to test if an environment variable is empty or unset is this:
     
    # ${parameter:?word}
    #
    : ${BUILDDIR:?"Need to set BUILDDIR non-empty"}  
    
    
    Here, if parameter ($BUILDDIR) is empty or unset, the expansion of word is written to the standard output and shell exits. The entire expression is an argument to the "colon command" (:) which simply evaluates its argument. According to UNIX historians, it is a derelict of good old days of the Bourne shell scripts which had every command start with colon.

    Tuesday, June 19, 2012

    How to find and replace a string in multiple files

    To find and replace a tag across multiple files from command-line in linux, consider this simple shell script:
    #!/bin/sh  
    today=`date -R`
    find . -type f \( -name "*.h" -o -name "*.cpp" \) -print | \
       xargs sed -i 's/{DATE}/'"$today"'"/g'
    
    
    We scan for regular C++ header and source files. We then pipe the list of files found into 'sed' editor that does line-by-line search and replace.

    The only non-trivial part here is the replacement string, '"$today"'. The inside double quotes are needed to let shell expand $today to its value.

    Wednesday, June 13, 2012

    How to insert spaces with Tab key with Vim

    Some projects require for one reason or another to use spaces instead of a Tab character to indent the C/C++ code. Most of the time it is related to the diffs that are generated by the CM systems. If you are a Vim user, you can configure your editor to insert spaces with Tab keystroke by adding these commands to your ~/.vimrc:

     set ts=4  
     set shiftwidth=4  
     set expandtab  
     set nowrap  
    

    This assumes that the width of desired tab is 4 characters. gVim is a popular GUI font-end for Vim editor. However, I found the way gVim stores its configuration into ~/.vimrc non-intuitive:
    • Go to your $HOME directory.
    • Start the shell terminal.
    • Start gvim from command-line.
    • Configure your settings the way you like them to be.
    • Save the setting to .vimrc with command
       :mkvimrc  
      
    The trick here is to run gvim from your home directory. Otherwise, gVim writes .vimrc file in the current directory where it was started from.

    Monday, May 28, 2012

    How to create a source tree patch with GNU diff/patch

    First, make a copy of your source tree:
    
      $ cp -R libfoo.orig/ libfoo.new/
    
    
    When you finished with modifications to libfoo.new/, generate GNU unified patch:
    
      $ diff -rupN libfoo.orig/ libfoo.new/ > libfoo-05282012.patch
    
    
    To generate a unified patch against the CVS:
    
      $ cvs diff -u > libfoo-05282012.patch
    
    
    The patch can be applied to the origianl source tree:
    
      $ cd libfoo/
      $ patch -p0 < libfoo-05282012.patch
    
    
    To revert the patch:
    
      $ patch -p0 -R < libfoo-05282012.patch
    
    

    Tuesday, September 13, 2011

    Technical Drawings with Dia

    Dia is an excellent multi-platform diagram drawing tool originally written by Alexander Larsson. Unlike Visio, it works well on Windows and Linux, and best part -- it is free.

    I have been using it for a good part of the last 10 years and always enjoy its functionality.

    The most unintuitive aspect of embedding Dia drawings into your Microsoft Word document or PowerPoint presentation is how to export the drawing to appropriate picture format.

    Before you start working on your drawing with Dia, change drawing setting to these:
    • File|Page Setup to:
      1. Paper Size: Letter
      2. Scaling: 45
    • Under View menu item:
      1. Select AntiAliased
      2. Unselect Snap To Objects
    Now, proceed with your drawing diagram. You can disregard the fact that it might span over multiple pages. When you are finished, go back to File|Page Setup and change Scaling of it to Fit to: 1 by 1. This will rescale your drawing to fit in a page. The reason for that is the physical constraint of Microsoft Word document which is page-oriented.

    Now you are ready to export your drawing from Dia internal XML format to one of the compressed graphics formats such as JPEG, GIF, or PNG.
    Open 'Export Diagram' dialog via File|Export. We are going to use PNG as graphics file format as it works well in the documents and on the web across all imaginable platforms.

    The trick is to select the right PNG format out of all available which are:
    • Cairo PNG (*.png)
    • Cairo PNG (with alpha) (*.png)
    • Pixbuf[png] (*.png)
    • PNG (anti-aliased) (*.png)
    The right format would be the last available, PNG (anti-aliased).

    When selected, press 'Save' button and then a little dialog 'diaw.exe' pops up to let you specify PNG Export Options. This is very important as you can set Image width of your final picture.

    For Microsoft Word document I set Image widht to 800 and let the dialog adjust the height.

    For PowerPoint presentation, set it to 1200 and also remember to have your document orientation set to Landscape in the File|Page Setup we did at the beginning.

    When you import the picture in your Word document, you can resize it to better fit the flow of your text.

    Friday, June 17, 2011

    Formatting Source Code with astyle

    astyle is a source code indenter, formatter, and beautifier for the C, C++, C# and Java programming languages. It is cross-platform and gets the job done pretty well.

    I use a combination of these switches to get code formatted to my liking:

    #!/bin/sh
    #
    # Name: indent++
    #
    astyle \
        --style=1tbs \
        --indent=tab=4 \
        --indent-switches \
        --indent-preprocessor \
        --convert-tabs \
        --break-blocks \
        --break-closing-brackets \
        --unpad-paren \
        --pad-header \
        --pad-oper \
        --pad-paren-out \
        --add-brackets \
        --align-pointer=type \
        --align-reference=type < $file > $file.indented
    
    mv $file $file.orig
    mv $file.indented $file
    

    Friday, January 21, 2011

    How to add Purify to automake project

    This post describes how to add Purify support to the Automake project.

    In order to instrument your automake project with Purify, you would need to perform following modifications to your project files:
    • add SUPPORT_PURIFY m4 macro to the project files
    • modify configure.ac
    • modify $rootdir/Makefile.am
    • add Purify-specific bootstrap script

    Add m4 macro to test Purify installation


    Under $rootdir create macros directory and add support_purify.m4 file:

    AC_DEFUN([SUPPORT_PURIFY],
    [
    dnl Name: support-purify.m4
    dnl
    dnl Description: Definition of SUPPORT_PURIFY m4 macro.
    dnl
    dnl
    
    AC_ARG_ENABLE(purify-linker,
    [AC_HELP_STRING([--enable-purify-linker],
    [Augment the linker with purify.])],
    [enable_purify_linker=$withval],
    [enable_purify_linker=no])
    
    if test "x$enable_purify_linker" = xyes ; then
      echo "Option enabled --enable-purify-linker=yes"
      AC_DEFINE([USE_PURIFY_LINKER],[],[Link-time support for Purify.])
      use_purify_linker=yes
    else
      use_purify_linker=no
    fi
    
    dnl ====================================================
    dnl Specify location of PURIFY
    
    AC_MSG_CHECKING(for purify)
    
    AC_ARG_WITH(purify,
    [ --with-purify=PATH Specify the prefix where purify is installed],
    ,
    test "$purify_PREFIX" && with_purify="$purify_PREFIX")
    
    test "$with_purify" &&
    test ! "$with_purify" = no &&
    purify_PREFIX="$with_purify"
    
    AC_MSG_RESULT($purify_PREFIX)
    AC_SUBST(purify_BIN)
    
    echo "purify_BIN is $purify_BIN"
    
    dnl ====================================================
    dnl Specify options for Purify
    
    AC_ARG_WITH(purify-options,
    [ --with-purify-options=ARG manually set PURIFY options to ARG],
    PURIFY_OPTIONS=$with_purify_options,
    PURIFY_OPTIONS="-follow-child-processes=yes -windows=no -cache-dir=${HOME}/tmp -always-use-cache-dir=yes -view-file=${HOME}/tmp/%v-%p.pv -messages=batch")
    
    AC_SUBST(PURIFY_OPTIONS)
    
    dnl ====================================================
    dnl Augment linker
    
    if test "x$enable_purify_linker" = xyes ; then
    echo "augment the linker"
    AUX_LINKER="${purify_BIN} ${PURIFY_OPTIONS}"
    echo "AUX_LINKER = $AUX_LINKER"
    fi
    
    AC_SUBST(AUX_LINKER)
    
    CCLD="$AUX_LINKER $CXX"
    CXXLD="$AUX_LINKER $CXX"
    
    AC_SUBST(CXXLD)
    AC_SUBST(CCCLD)
    
    echo "In macro SUPPORT PURIFY: CXX = $CXX"
    echo "In macro SUPPORT PURIFY: CXXLD = $CXXLD"
    dnl ====================================================
    dnl End of Purify macro definition
    ]
    )
    

    Modify configure.ac


    m4_include([macros/support_purify.m4])
    SUPPORT_PURIFY
    

    Modify $topdir/Makefile.am


    Add 'bootstrap-dev-purify' and 'macros/support_purify.m4' to your EXTRA_DIST target.

    Purify-specific bootstrap script


    Modify your bootstrap script to enable Purify instrumentation:
    autogen.sh
    configure --prefix=$INSTALLDIR --enable-purify-linker=yes
    make
    

    Conclusion


    Now you can run 'bootstrap-dev-purify' script to let automake test Purify on your system and if successful, instrument your project with Purify-enabled object code.

    Tuesday, January 4, 2011

    Qt4 SDK packages Fedora Core 14

    I took me some cycles to figure out which RPM packages to install under Fedora Core 14 running GNOME desktop to begin development with Qt4 libraries.

    Here is the bare minimum:
    • qt-4.7.1-7.fc14.i686
    • qt-x11-4.7.1-7.fc14.i686
    • qt-devel-4.7.1-7.fc14.i686
    And documentation, examples, etc:
    • qt-doc-4.7.1-7.fc14.noarch
    • qt-demos-4.7.1-7.fc14.i686
    • qt-examples-4.7.1-7.fc14.i686
    To develop with Qt4 IDE:
    • qt-creator-2.1.0-4.rc1.fc14.i686 

    To develop with WebKit:
    • qt-webkit-4.7.1-7.fc14.i686
    • qt-webkit-devel-4.7.1-7.fc14.i686
    To develop for smart phones, netbooks, and non-mobile personal computers:
    • qt-mobility-1.0.1-3.fc14.i686
    • qt-mobility-devel-1.0.1-3.fc14.i686
    • qt-mobility-doc-1.0.1-3.fc14.noarch

    Tuesday, November 9, 2010

    FedoraCore VirtualBox Guest setup

    How to setup FedoraCore Guest in VirtualBox inWindowXP host.
    • Download VirtualBox installer from Oracle web site and install Oracle VM VirtualBox.
    • Launch Oracle VM VirtualBox.
    • Change the default Folder location for HardDisk and Machine:
      • Go to File->Preferences->General
      • Change location of Default Hard Drive Folder.
        • c:\MyStuff\VirtualBox\HardDisks
      • Change location of Default Machine Folder.
        • c:\MyStuff\VirtualBox\Machines
    • Create new virtual machine:

      • Click on New icon.
      • On Welcome screen, click Next.
      • On VM Name and OS Type screen, enter
        • Name: salmon
        • OS Type:
          • Operating System: Linux
          • Version: Fedora
        • Click Next
      • On Memory screen, 
        • set the Base Memory Size to 1024 MB.
        • Click Next
      • On Virtual Hard Drive screen
        • Check Boot Hard Drive
        • Select Create new hard disk
        • Click Next
      •  On Hard Disk Storage Type screen
        • Select Dynamically allocated
        • Click Next
      • On Virtual Disk Location and Size screen
        • Make sure the location of salmon is under c:\MyStuff\VirtualBox\HardDisks
        • Set the initial size to 32 GB (10GB is the bare minimum).
        • Click Next
      • On Summary screen
        • Click Finish
    • Adjust Virtual Machine salmon settings
      • Click on Setting icon
      • In salmon - Settings screen 
        • Select System/Motherboard tab 
          • Under Boot Order section
            • Uncheck Floppy entry
          • Under Extended Features
            • Leave Enable IO APCI unchecked
        • Select System/Acceleration tab 
          • Make sure 
          • VT-x/AMD-V is enabled
          • Nested Pages is enabled

        • Select Display/Video tab
          • Enable 3D Acceleration
        • Select Display/Storage tab
          •  Under Storage Tree in IDE Controller, select Empty CD icon.
          • To install directly from physical Fedora i386 DVD, you need to connect a physical host device (such as DVD drive) to your virtual machine. For that, under Attributes:


            • Click on a little DVD icon to the right of the CD/DVD Drive selection. Click on "Host Drive D:".  The IDE Controller child entry will change to 'Host Drive D:' selection.
            • Select Passthrough option. 

        • Select Audio tab.

          • Check 'Enable Audio' box
          • Select 'Windows DirectSound' audio driver
          • Select 'ICH AC97' audio controller
    • Insert Fedora Core DVD disk in DVD drive.
    • Click on the Start button to begin installation
      • Set Hostname to your Host machine name (with full domain name)
      • Choose Customize now option and select
        • Choose GNOME Desktop Development
        • Under Applications select
          • Authoring and Publishing
          • Editors
          • Graphics Internet
          • Graphics
          • Office/Productivity
          • Sound and Video
          • Text-based Internet (for wget)
        • Under Development select
          • Development Libraries
          • Development Tools
          • Fedora Packager
          • GNOME Software Development
          • Web Development
          • X Software Development
        •  Under Servers select
          • MySQL Database
          • Network Servers
          • Printing Support
          • Server Configuration Tools
          • Web Server
          • Windows File Server
        • Under Base System in addition to defaults, select
          • Administration Tools
          • System Tools
        • Under Languages
          • add Russian Support
      • Continue with installation (grab a sandwich or something...). This will take a while.
    • Reboot after installation is complete and
      • Create user account
      • Setup Network Time Protocol server
      • Enable sudo access for your login account:
        • $ su -
        • Password: {your superuser password}
        • # /usr/sbin/visudo
        • {edit /etc/sudoers file and add} 
          • {username}  ALL=(ALL) ALL


    • Install Guess Additions
      • Guest Additions add very useful functionality:
        • X server driver with higher screen resolution
        • Seamless cut-n-past between Host and Guest OSes
        • Mouse driver that integrates host and virtual desktop spac
            To install Guest Additions:
      • Install development tools to be able to compile kernel drivers:
        • # yum groupinstall "Development Tools"
      • Check if running guest VM window has its menu bar at the top shown. If not, shutdown the VM machine and re-enable it for the guest.
      • In the Oracle VM VirtualBox menu, click on Devices->Install Guest Additions 
      •  
      • In the Guest Virtual Machine (VM), GNOME desktop will detect new media inserted, VBOXADDITIONS_3.2.10_66523.
      • Click Cancel to dismiss the dialog.
      • Open terminal with Applications->System Tools->Terminal

      • $ cd /media/VBOXADDITIONS_3.2.10_66523
      • $ sudo sh ./VBoxLinuxAdditions-amd64.run
      • When Guest Additions installation is complete, right click on CD icon on the desktop and Eject it.
      • Release the cursor and in the Oracle VM VirtualBox menu, click on Devices->CD/DVD Devices click on 'Host Drive D:' to unmount GuestAdditions.iso image.
      • In the Virtual Machine, edit /etc/X11/xorg.conf to add screen resolutions that matches your primary desktop/laptop screen.
        $ sudo vi /etc/X11/xorg.conf
        
        Section"Screen"
        SubSection "Display"
        Modes "1900x1200" "1280x1024" "1024x768" "800x600"
        Depth 24
        EndSection
        ...
        EndSection
        
      • Reboot the Virtual Machine. Now you should have the resizable desktop with fullscreen mode available as well. 
    • From you account in the VM, 
      • Disable Firewall.
      • Set SELinux mode to Permissive.
    • To setup USB pass-through support,
      • In the Linux guest VM, Create 'usb' group and add yourself as a user to that group.
      •  Shut down guest VM
      • In the VirtualBox window manager, select the virtual machine and open its Settings dialog.
      • Under USB settings,
        • Enable USB Controller
        • Enable USB 2.0 (EHCI) Controller
        • Add a USB Device Filter
        • Enable the filter
        • Edit filter details and set Remote to 'Any'

      • Restart the guest VM
      • When Linux desktop appears, have focus on the desktop
      • Insert the USB stick.
      • First time around, Windows XP would detect a new hardware profile. Go on with driver installation to install VirtualBox USB driver.
      • In the guest VM, under Devices tab, select the USB stick.
      • The USB device should appear on your Linux desktop as icon.

      • NOTE: For a while, I was getting this error from VirtualBox's guest VM:
        USB device SanDisk USB U3 Cruzer with 
        UUID [some id] is busy with a previous request. 
        Please try again later.
        
        Result code: E_INVALIDARG (0x80070057)
        Component:   HostUSBDevice
        Interface:   IHostUSBDevice {some id}
        Callee:      IConsole {some id} 
        In my case the error was ultimately resolved by creating the "usb" group under guest VM as outlined above. For further information, please, refer to VirtualBox bug #3033 (USB device not available to Guest)

    Strip leading path with GNU tar

    Sometimes, when I untar an archive file, I need to strip leading path from the archived files. For example, if my archive is stored on a DVD disk the following command would unpack it to my home directory and strip the leading path name:

    shell> cd $HOME
    shell> tar --extract --file /mount/Backups/home-bkp-11082010.tar.gz --strip-components=1 

    Essentially, if my original backup had a  file vlg/foobar.txt, the vlg/ part of the path would be stripped out.

    This comes very handy if the backup file was created with something like:

    shell> cd /home
    shell> sudo tar xvfz home-bkp-11082010.tar.gz vlg