Archive for the ‘Uncategorized’ Category

Change hue/color of icon using image magick

Sunday, July 31st, 2011 by lane

You can use the -modulate option to change the hue of an icon, but it does not, for some unknown reason, preserve the icons alpha channel. So here is the command line option to change the hue of an icon while preserving the alpha channel:

convert icon.png -modulate 100,100,50 -alpha off icon.png -compose CopyOpacity -composite PNG32:output.png

The last option to the modulate option changes the hue. Change it from 50 to whatever you want to get the hue you want. A value of 100 will leave the hue unchanged.

From the image magick documentation:

The hue argument causes a “rotation” of the colors within the image by the amount specified. For example, 50 results in a counter-clockwise rotation of 90, mapping red shades to purple, and so on. A value of either 0 or 200 results in a complete 180 degree rotation of the image. Using a value of 300 is a 360 degree rotation resulting in no change to the original image

Garmin Connect on Linux

Thursday, July 21st, 2011 by lane

I have been wishing for Garmin to support Linux with their Communicator Plugin for quite some time. In fact, I have even considered writing the firefox plugin to enable Linux support several times, but just haven’t been able to find the time to do it, plus maintain it, etc. So I have been using Garmin Connect in a virtual windows machine. It has been painful, but the other options were even less appealing to me.

Yesterday, however, while looking into adding Garmin Communicator support into Routometer, I did yet another Google search to see if someone else had written a Linux plugin, and what do you know, but YES. Check it out at Linux Garmin Communicator Plugin.

I tested it out. Fortunately it supports my watch, the Forerunner 305. I downloaded the RPMS and they installed without issue. I went to about:plugins with Firefox, and sure enough it was there. I went to Garmin Connect and the first message it gave was browser not supported. I restarted Firefox, and that error went away. The next problem, however, was that it said no devices were detected. I had long ago added ‘garmin_gps’ to my modprobe blacklist, and looking at the RPMS it seems to create an blacklist conf file for you. I was not sure the problem, so I looked into Garmin Tools command line programs to see if I could figure it out. Running ‘garmin_get_info’ returned nothing. So I unplugged and replugged in my Garmin Forerunner 305. Running ‘garmin_get_info’ this time produced a screen full of information. I returned to Garmin Connect and this time it detected my device. I clicked to upload new activities. The watch beeped a couple times and then the progress bar on Garmin Connect froze. So I returned to the command line and tried the ‘garmin_save_runs’ command. That downloaded everything just fine. So I reloaded Garmin Connect and tried uploading again. This time it made it through. I did not have any new runs on my watch, however, so it wasn’t a complete test.

I decided to go on a run just to test it out. I went on a short 4 mile loop. Upon returning I plugged it in and tried uploading. Everything seemed to work. It found the one new run and appeared to upload it. When I clicked the “Activities” link, however, to view it, it wasn’t there. Maybe I didn’t let it finish uploading. In retrospect I can’t be sure what I did, but the run was not there. So I tried uploading again. This time, however, it WORKED!!!! Below is my first run uploaded to Garmin Connect using Firefox on Linux. While the first try was not flawless, I could not be happier. Thanks to all those who have worked on it. Now I can add support for uploading hand-drawn courses in Routometer directly to your Garmin.

Arduino Uno on Fedora Linux

Thursday, January 27th, 2011 by lane

Here are some notes on things I did to get Arduino working on Fedora Linux:

  • Install the Arduino software
    sudo yum install arduino
    
  • Edit udev rules so that you have permission to talk to the serial port. To do this I added the following line to /uetc/udev/rules.d/60.rules:
    KERNEL=="ttyACM*", MODE="0666"
    

Ubuntu BeagleBoard xM

Thursday, December 9th, 2010 by lane

Here is nice summary of package manage commands at Ubuntu for Fedora Users.

Install Ubuntu according to BeagleBoardUbuntu.

For network, edit /etc/network/interfaces to include

auto usb1
iface usb1 inet dhcp

Then restart networking. Then run

apt-get update

For X

apt-get install xfce4 gdm xubuntu-gdm-theme xubuntu-artwork xserver-xorg-video-omap3

To run

apt-get install python-gst0.10 gstreamer0.10 gstreamer0.10-plugins-good

For development:

apt-get install gcc libxext-dev libtool autoconf automake pkg-config python-dev libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev git libgdk-pixbuf2.0-dev libpng-dev

For extra:

apt-get install rsync emacs openssh-client midori apt-file

Autologin

Create a file called /etc/gdm/custom.conf

[daemon]
AutomaticLoginEnable=true
AutomaticLogin=YourUserName
TimedLoginDelay=0

Display

Links:

For display, you edit the boot.cmd file in the uboot directory on the boot partition. The dvi_mode variable syntax is (taken from drivers/video/modedb.c):

	Valid mode specifiers for @mode_option:
 *
 *	x[M][R][-][@][i][m] or
 *	[-][@]
 *
 *	with , ,  and  decimal numbers and
 *	 a string.
 *
 *      If 'M' is present after yres (and before refresh/bpp if present),
 *      the function will compute the timings using VESA(tm) Coordinated
 *      Video Timings (CVT).  If 'R' is present after 'M', will compute with
 *      reduced blanking (for flatpanels).  If 'i' is present, compute
 *      interlaced mode.  If 'm' is present, add margins equal to 1.8%
 *      of xres rounded down to 8 pixels, and 1.8% of yres. The char
 *      'i' and 'm' must be after 'M' and 'R'. Example:
 *
 *      1024x768MR-8@60m - Reduced blank with margins at 60Hz.

Python DPMS

Friday, December 3rd, 2010 by lane

There have been several occasions where I have needed to control the power state of my monitor (LCD or CRT) programatically. One time was for a custom LCD digital picture frame that I made. I wanted to turn off the LCD after a certain timeout period and turn it back on whenever a motion sensor produced an event. For that project I used the “xset” command line program and used a command like:

xset dpms force <on|off>

to turn it on and off. That worked, but this time around I wanted to do it programmatically rather than dropping to a system shell. I downloaded the source code for xset and found they were interfacing to the DPMS X11 extension. So I downloaded the source to libXext and found the DPMS API. It is a simple API, so I created some Python bindings to it and have published the results over at github. You can checkout the python-dpms project page over at github or download the source tarball and build it.

It is simple to turn on and off the monitor from python now:

import dpms, time
d=dpms.DPMS()
time.sleep(1) # this is necessary to prevent your last key press that launches this from waking the monitor right back up
d.ForceLevel(dpms.DPMSModeOff) # turn monitor off
d.Info()
#d.ForceLevel(dpms.DPMSModeOn) # turn it on

You will need to save this to a file and run it non-interactively because the interactive shell will cause it to wake up instantly. When you run it non-interactively, it will turn off your monitor and then you can press any key to wake it back up.

Here is the README file from the project:


ABOUT
=====

This is python bindings to the DPMS X11 extension module for controlling
your monitor power savings state.

The DPMS interface lets you control the power level of your monitor
(On, Standby, Suspend, or Off).  It is a simple interface that lets
you get/set timeouts of inactivity to enter these states or you can
force it to enter any of the states.

See example.py on how to use it. This file should be sufficient on how
to use it. It first shows how to query all the different settings and
then shows how to set them.

See also 'man xset' for a program that lets you modify the DPMS state
from the command line.

INSTALL
=======

Install libXext and python development packages installed. For
example, on RedHat/Fedora:

    yum install libXext-devel python-devel

On Ubuntu:

    apt-get install libxext6-dev python-dev

Then run:

    python setup.py build

Then as root, run:

    python setup.py install

That's it. Now run:

    python example.py

to test it out.

The included example.py shows how easy it is to use:

import dpms

d = dpms.DPMS() # to use the current display, or alternatively DPMS(":1")

# print up the display
print "Display         :", d.display()

# query extension, should return True as the first element
print "Query Extension :", d.QueryExtension()

# query Capable, not sure what it does
print "Capable         :", d.Capable() 

# query current version
print "Version         :", d.GetVersion()

# query the current state of things
(level, enabled) = d.Info()

print "DPMS enabled    :", enabled
if(level == dpms.DPMSModeOn):
    current_level = "On"
elif(level == dpms.DPMSModeStandby):
    current_level = "Standby"
elif(level == dpms.DPMSModeSuspend):
    current_level = "Suspend"
elif(level == dpms.DPMSModeOff):
    current_level = "Off"
else:
    current_level = "Unknown (%d)" % level

print "Current Level   :", current_level, "(", level, ")"

# query the current timeout settings
(standby, suspend, off) = d.GetTimeouts()
print "Timeouts"
print "  Standby       :", standby
print "  Suspend       :", suspend
print "  Off           :", off

# We have queried everything, now we will set everything back to its
# current state. We set back to the current state so as not to alter
# any state and so that you can see examples of setting state.

# set the timeout settings
d.SetTimeouts(standby, suspend, off)

# enable/disable DPMS
if(enabled):
    d.Enable()
else:
    d.Disable()

# force DPMS to a certain level
d.ForceLevel(level)

# if you wanted to force the monitor off, you could
#d.ForceLevel(dpms.DPMSModeOff)

# to force it back on
#d.ForceLevel(dpms.DPMSModeOn)

# You can also suspend or standby
#d.ForceLevel(dpms.DPMSModeSuspend)
#d.ForceLevel(dpms.DPMSModeStandby)

If you run python example.py, you will see output like:

Display         : :0.0
Query Extension : (True, 0, 0)
Capable         : True
Version         : (1, 1)
DPMS enabled    : True
Current Level   : On ( 0 )
Timeouts
  Standby       : 0
  Suspend       : 0
  Off           : 0

So just like that I can now turn on and off the monitor from my python programs. If you are not using python but C/C++, the /usr/include/X11/extensions/dpms.h shows how simple the API is, so don’t be afraid to use it.

X Forwarding Problem with ssh

Wednesday, June 2nd, 2010 by lane

Recently I ssh’d into one of my servers using the command ’ssh -X hostname’ from the client. I then tried to launch an X11 application but received the error:

Gtk-WARNING **: cannot open display:

I then found the DISPLAY environment variable was blank. A little searching around and I found that the I needed the xauth program installed. A

yum install xorg-x11-xauth

on the server did the trick. Now when I ssh in using the -X option, X11 applications run fine.

emacs font too large in Fedora linux

Monday, April 19th, 2010 by lane

Default emacs font on Fedora these days is way to big. I added the following to my .Xresources file to solve the problem:

emacs.FontBackend: xft
emacs.font: DejaVu Sans Mono-9
emacs.geometry:    80x80

I don’t think the xft option is necessary, but changing the DejaVu Sans Mono from 12 point to 9 point is what I wanted. The geometry sets the size of the buffer on startup.

Dynamic methods in Python

Saturday, December 26th, 2009 by lane

To dynamically control the methods of a python class, you overload the __get_attribute__() method. Then you can do whatever you want with your class as in this example:

class myclass(object):
    def __getattribute__(self, name):
        try: # first check if this object as the requested method
            return object.__getattribute__(self, name)
        except AttributeError: # if not, do something else
            raise

#    def __setattr__(self, name, val):
#       pass

Installing Fedora 11 (F11) on Macbook Air

Monday, September 21st, 2009 by lane

I have a previous post on installing Fedora 10 on the Macbook Air. I recently upgraded to Fedora 11 through yum. Overall that went well. I followed the yum upgrade instructions without a hitch.

When I reboot into F11, sound didn’t work and multitouch stopped working. To get sound working again, I changed /etc/modprode.d/sound.conf to

options snd_hda_intel model=asus-a7m

and rebooted.

To get multitouch working, I deleted the /etc/X11/xorg.conf file I created previously and in GNOME changed my System->Preferences->Mouse->Touchpad settings to enable double and triple finger clicking.

System Message Bus hanging on start and LDAP recovery

Sunday, February 1st, 2009 by lane

I have a server that has twice filled up the primary hard drive partition and then caused me several hours of debug to figure out what happened.  The time between these two events was long enough that I had to go through the same debug path twice, and I only realized after the fact that I should have known.

Here were the symptoms:

  • Things were slow to start
  • System Message Bus took many minutes (probably more than 10)
  • LDAP server would not start.  It had a db recovery message. Ran
    /usr/sbin/slapd_db_recover -v -h /var/lib/ldap

    command to recover it after clearing out some space.