Wednesday, December 30, 2009

Censoring Google search results in chromium

Ever find yourself clicking one of those "experts exchange" links? I know you have. Want to avoid that rise in blood pressure? No problem.

I'm using the nightly build of chromium these days, instructions follow:

1. Install the Chrome Stylist extension. (https://chrome.google.com/extensions/detail/pabfempgigicdjjlccdgnbmeggkbjdhd)

2. Open the Chrome Stylist options (Wrench Menu->Extensions, click 'options')

3. 'Add New Style':
- prefix: http://google.com/search
- css:
li h3 a[HREF*="http://www.experts-exchange.com/"] {display : none ! important }
A[HREF*="http://www.experts-exchange.com/"]:after { content: " [IDIOT WARNING]"!important ; color: red }

All done - enjoy ;)

Wednesday, October 07, 2009

Take the Red PIL Neo...

OK - so I have a directory filled with around a thousand fonts.  Which is a Good Thing.  They're even separated into sub directories based on the first letter of the font name.  So what's the problem you ask?  All of this seems like good stuff.  Well, the file names themselves are complete gibberish.  gobbledygook.  garbage.  Which is a Bad Thing.  I'm not installing all 1000 fonts.  And I sure as hell ain't gonna rename them by hand.  Forget it.

So, enter magic and PIL.  Python's magic module allows file typing, and PIL's ImageFont module lets you grab the font information.  An violá we have a font renamer in Python:


#!/usr/bin/env python
#
#  font_renamer.py - utility to rename fonts based on name.
#
#  WARNING!!!  This script renames your fonts IN SITU.  If in doubt,
#  make a copy of the fonts directy first BEFORE you run the script.
#  You have been warned.
#
#  Depends on PIL and magic (not magic pills).
#
#  A big thank you to the python-list, who provided the snippets
#  I needed to piece this together!
#
#  (C) 2009 Chris Mohler
#
#  This program is free software: you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation, either version 3 of the License, or
#  (at your option) any later version.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.

#  You should have received a copy of the GNU General Public License
#  along with this program.  If not, see .

import sys, os, magic

from PIL import ImageFont

def rename_ttf (file):
    # open font with PIL
    f = ImageFont.truetype(file, 1)

    # fashion a new file name - family + style
    newfilename = f.font.family.replace(' ', '_') + '_'
    newfilename = newfilename + f.font.style.replace(' ','_') + ".ttf"

    # bust the old filename and path up
    filet = os.path.split(file)

    # new tuple with old path and new filename
    newfilet = filet[0:-1] + (newfilename,)

    # join the tuple together
    newfile = os.sep.join(str(x) for x in newfilet)
   
    # rename the font
    os.rename(file,newfile)


def main() :
   
    # we only want one argument, and it should be a dir
    if len(sys.argv) == 2:
        if os.path.isdir(sys.argv[1]):
            folder = sys.argv[1]
        else:
            print "Usage: font_renamer.py directory"
            exit
    else:
        print "Usage: font_renamer.py directory"
        exit

    # walk the dir
    for root, dir, files in os.walk(folder):
        for file in files:
            # initialize magic (really - it IS magic)
            m = magic.open(magic.MAGIC_NONE)
            m.load()
           
            # find the file type
            type = m.file(os.path.join(root, file))

            # if it's a TTF, then let's rename it
            if type == "TrueType font data":
                rename_ttf(os.path.join(root, file))

# hold on to your ass, here we go
main()



I tested on Ubuntu 9.04, but it uses the os module -  so with any luck you MS/OSX folks have a free batch font renamer as well.  Heed the warning in the script well my friends, heed it well.   Don't come crying to me if this thing eats your fonts or your kittens.

GPL v3 is probably overkill, but at least it's not ambigous.  And hey - if this saves your ass (or an hour of your time), my Paypal account is never full :)

Sunday, September 20, 2009

Update your BIOS from Ubuntu (or really, without windows)

OK - so in the process of mucking around to see what's killing my system, I decided a BIOS update might be a good idea -  I was using A01 and they'r eup to A06 these days.  One small hitch - the update comes as - you guessed it - a EXE file.

What to do?  Virtualbox is a no-go, because of course the hardware that the guest see is *virtual* (duh).  Make a small partition for XP?  Hell no.  Simlple solution - remaster a DOS boot disk with the BIOS update.

Step 1 - download your BIOS update.  BE SURE THAT IT WILL OPERATE IN DOS.

Step 2 - download a DOS boot image:
http://www.bootdisks.us/ms-dos/5/ms-dos-bootable-cd-images.html

I chose DOS 6.22.

Step 3 - install isomaster (sudo aptitude install isomaster)

Step 4 - open the DOS iso in isomaster, add the BIOS update, do CTRL-S to save the new image.

Step 5 - burn the ISO to disk.  Don't just copy the ISO to disk - burn an image.  But you knew that already ;)

Step 6 - boot from the new CD.  At the prompt, switch to the CD (drive R: if you used DOS 6.22).  Run the BIOS updater.  Dance around on one foot while sacrificing a chicken.

All done :)  While technically you are not using Ubuntu to update the BIOS, you're not having to nstall windows either so count your blessings!

Saturday, September 19, 2009

Lobotomy

OK - so I have some bad, bad RAM.  Getting some new modules ASAP, but in the meantime, the 'memmap' kernel parameter is serving me well.

I now have this line in /boot/grub/menu.lst:

# kopt=root=UUID=[some stuff] memmap=140M$580M memmap=140M$1600M ro

I've added two memmap options to the end.  The pseudo-syntax is [how much][unit]$[where][unit].  So I'm sitting on 140 megs starting at 580 megs and also 140 megs starting at 1600 megs.

run 'sudo grub-update' to apply the changes after editing menu.lst.  'free -m' will now report a missing ~280MB upon reboot.  

Now the laptop and I have something on common - holes in our memory ;)

Wednesday, September 16, 2009

GIMP plus Python = fun



My latest GIMP plug-in:
Palette to Image
http://registry.gimp.org/node/18629

I was looking for a quick way to dump a palette into an image - I had created a GIMP palette of Union inks (for screenprinting) and wanted a quick reference image for third parties. I could not find a built-in function, so this plugin was born: "Palette to Image".

The Python-GIMP bindings are quite good - anything found in Help->Procedure browser can be called from a plug-in. In Python, just take the procedure name, put pdb. on the front, and change dashes to underscores. For example in the browser 'gimp-image-new()' becomes 'pdb.gimp_image_new()'. Easy :)

My other python plug-ins:

Export Layers as PNG
http://registry.gimp.org/node/18440

Measure Active Path
http://registry.gimp.org/node/17235

Import Kuler (ASE) palettes
http://registry.gimp.org/node/10325

Find and Replace Text
http://registry.gimp.org/node/12212

Count tiles for a mosaic
http://registry.gimp.org/node/15080

Add Rule Of Thirds guides
http://registry.gimp.org/node/11567

Image courtesy of http://www.mahvin.com

Friday, August 14, 2009

WTF - dog size?

OK - so we're in Memphis now, searching for an affordable house/duplex to rent. It's been challenging to say the least. One little detail has been irking me: what does it matter what size my dog is? I'd like to hear *one* rational explanation of why size is a factor.

Saturday, August 08, 2009

Wiimote on Ubuntu 8.10
















Been a while - forgot I even *had* a blog ;)

Anyway, I decided that packing boxes required music. Since my laptop (Vostro 1500) has bluetooth, and I have Wiimote handy I decided that it was time to hook up the Wiimote as a remote control.

A few details on the setup:
- I'm using XFCE (Gnome is really getting on my nerves lately!)
- My preferred media player is Amarok
- I've already set up the multimedia keys on the front of the laptop, which saved me a step in getting the Wiimote working.

OK - first things first. I already had cwiid installed - you need to install this first. Google around :) Next, I added a udev rule:
KERNEL=="uinput", GROUP="uinput"
I put mine in /etc/udev/rules.d/91-uinput-cr33.rules

Next, I added a group 'uinput' and added myself and root to the group.

Then I restarted udev - which was a mistake ;) Better to reboot (unless of course you LIKE watching Xorg barf over and over...).

At this point, I was able to run the command 'wmgui' and connect to the Wiimote. So far, so good - pressing buttons lights up the wmgui interface. Killed wmgui.

Now - the tricky part: getting the buttons to control Amarok. Like I said above, I already had the media keys on the front of the laptop working. IIRC, in Applications->Settings->Settings Manager, I went to the Keyboard settings, then the Shortcuts tab. I don't remember exactly where I got the keycodes (maybe 'showkey -k' on VT1), but my shortcuts look like:
amarok XF86AudioMedia
aumix -v0 XF86AudioMute (similar for volume up/down)
dcop amarok player next XF86AudioNext (similar for other playback buttons - note the use of dcop)

So, with that already set up, all I needed was a conf file for wminput. Easy right? not so much - I finally found a list of all keys for wminput in the source code, then matched them up to the keycodes given by 'showkey -k': http://abstrakraft.org/cwiid/browser/trunk/wminput/action_enum.txt

Once I had my amarok.conf file, I started wminput thusly:
wminput -w -c /home/cr33/amarok.conf

So my amarok.conf ended up looking like this:
#acc_ptr

Wiimote.A = KEY_PLAYPAUSE
Wiimote.B = KEY_STOPCD
Wiimote.Up = KEY_VOLUMEUP
Wiimote.Down = KEY_VOLUMEDOWN
Wiimote.Left = KEY_LEFT
Wiimote.Right = KEY_RIGHT
Wiimote.Minus = KEY_PREVIOUSSONG
Wiimote.Plus = KEY_NEXTSONG
Wiimote.Home = KEY_MEDIA
Wiimote.1 = KEY_MUTE
#Wiimote.2 = KEY_MUTE

#Plugin.led.Battery = 1
Plugin.led.Button = BTN_2

#Plugin.acc.X = REL_X
#Plugin.acc.Y = REL_Y
Notice that #acc_ptr is commented out - this keeps the Wiimote tilt from affecting the pointer position. I also ended up commenting out Button 2 - as you can see, I've installed the nifty led plugin, which can be found here:
http://abstrakraft.org/cwiid/attachment/ticket/65/led.py
It needs to go into ~/.cwiid/plugins (note the lowercase cwiid - some of the docs are wrong)


I edited the plugin on lines 9-10 to look like:
Battery = 1
Button = cwiid.BTN_2
That's probably wrong - since I get an error on starting wminput: "Invalid plugin button: led.Button". Oh well - it works though. Pressing Button 2 on the Wiimote shows me how much battery charge is left.

Anyway, that's a wrap. I just wanted to document this, since it look longer to get this working than it should have :)

Image courtesy of: http://nand-magazine.net