Akom's Tech Ruminations

Various tech outbursts - code and solutions to practical problems

Linux Simple flat file site search in PHP/Smarty

Posted by Admin • Wednesday, January 19. 2011 • Category: Linux
Sometimes using a real search implementation (Lucene, Sphinx) is just too much. The particular site I was working on is something like 30 pages, it's maintained as flat files (Smarty templates, but it's basically HTML on disk), and it really, really should not require megabytes of code and cron jobs to be able to search it!

That said, this is a simple search solution - it makes a lot of assumptions:

Continue reading "Simple flat file site search in PHP/Smarty"

Linux Predictable ALSA numbering of USB sound cards

Posted by Admin • Wednesday, January 12. 2011 • Category: Linux
I have 3 rather cute Monoprice usb sound cards for use by mmpd (client I wrote for multiple mpd instances). The great thing about them is that for $9 you can just keep adding zones to your music systems. The bad news is, UDEV will reorder sound cards on boot as it pleases.

Zones changing would be survivable in itself (reboots are rare), but I also have a webcam and an onboard sound card that I don't use - so sometimes the numbers I've configured mpd to use aren't even valid sound cards! On to the continuing search for a working solution

Continue reading "Predictable ALSA numbering of USB sound cards"

Linux Fixing digitemp with LinkUSB on kernels after 2.6.32-24

Posted by Admin • Tuesday, January 11. 2011 • Category: Linux
As many people have discovered, kernels after 2.6.32-24 changed the USB-RS232 serial driver to not set hardware flow control (RTS/DTS) flags. No doubt there was a good reason. Unfortunately, digitemp and owfs don't enable it either, also probably for a good reason - at least when applied to older devices. What this means is that now when you try to use a LinkUSB (and probably other DS9097U type hardware behind USB to Serial converters), digitemp and owfs no longer work.

Let's apply a time-tested hackish approach.

Continue reading "Fixing digitemp with LinkUSB on kernels after 2.6.32-24"

Linux How to take down your pfSense firewall with one checkbox

Posted by Admin • Saturday, January 1. 2011 • Category: Linux
Simple: create a Traffic Shaper queue but forget to choose a queue parent.

Your firewall will not pass any packets across, and you'll have no idea what hit you.

Linux Verizon Wireless tethering Ubuntu Karmic to a Storm 2

Posted by Admin • Friday, April 2. 2010 • Category: Linux
This topic is fairly well described, so this is just a quick how to for me. (This is for USB, I am not attempting bluetooth this time) UPDATE: I now use berry4all instead of the below. It just works, and there is a GUI


Old Way:

  1. sudo apt-get install libbarry0 barry-util barrybackup-gui
    Chances are you already have the first two in a karmic install, and you may not even need barrybackup-gui. I did not need to add any new apt repositories
  2. if the phone requires a password, edit /etc/ppp/peers/barry-verizon and change the pty line to read
    pty "/usr/sbin/pppob -P My_Password"
    Yes there is a password line in that file, but it doesn't seem to do anything, and I don't know how to use variables in a pppd script :-)
  3. sudo pppd call barry-verizon
    You should see the progress and the IP's relevant to the connection. If you're having trouble, add debug:
    sudo pppd debug call barry-verizon
Note1: In my experience, after I kill the pppd connection I can't reconnect until I momentarily unplug the phone. Also, mass storage mode is not necessary.

Note2: These steps should be similar for most providers. Look at /etc/ppp/peers/barry-* to see the predefined provider scripts.

Note3: I believe that the connection will fail miserably if you have any other network connection active on the PC besides the tethered phone.

Note4: I am posting this using my blackberry!

Linux Postfix satelite mail configuration with special needs

Posted by Admin • Monday, February 15. 2010 • Category: Linux
OK so I have special needs. (Either that or I am just oblivious to a working example of this).

My needs are:
  1. Do not receive inbound mail
  2. Do not deliver mail locally at all
  3. Send all outbound mail through an upstream relay (ISP's smtp)
  4. Qualify local addresses with a valid domain name (ISP's smtp will reject invalid domains)
  5. Map some local addresses to convenient aliases (distribution lists in the real mail system - google apps in this case)


Doesn't seem so hard, right? So I started with the postfix "Satelite System" option in ubuntu installer, and then...

Continue reading "Postfix satelite mail configuration with special needs"

Linux Software RAID in Ubuntu Karmic 9.10

Posted by Admin • Monday, February 15. 2010 • Category: Linux
I am writing this down because it was somewhat hard to figure out how much of the HOWTO's out there are out of date. This is not particularly difficult, but it's my first RAID setup and this blog is my notepad. I am setting up a RAID1 on a Dell Precision 490 with two brand new 500GB SATA drives.

First I tried using BIOS RAID. My system doesn't have a true RAID controller card and after some trial,error and googling I decided to forget it and go with an industrty standard (MD) Linux software RAID. I reset my drives to non-raid in the BIOS, popped in Ubuntu server x64 CD and went on ahead.

Continue reading "Software RAID in Ubuntu Karmic 9.10 "

Linux MySQL replication dies with ERROR 1201 (HY000): Could not initialize master info structure

Posted by Admin • Friday, February 12. 2010 • Category: Linux
On a fine happy morning I am greeted with an alert that slave is not running. Running start slave yields this:
ERROR 1201 (HY000): Could not initialize master info structure; more error messages can be found in the MySQL error log
Enabling the log yielded nothing. Googling yielded This Page that helped me a lot, but I didn't have to do quite as much work all over again. Here is what I did.

Continue reading "MySQL replication dies with ERROR 1201 (HY000): Could not initialize master info structure"

Linux Disabling X server autostart (gdm) on Ubuntu Karmic (9.10)

Posted by Admin • Monday, November 16. 2009 • Category: Linux
There are many reasons one may wish to do this - running their desktop installation as a sever (temporarily perhaps), solving some video issues... or just doing it to get that facet of control back. I, for instance, prefer to run X with "startx" when I'm ready to do so. I do not enjoy a black screen when the latest intel video driver doesn't work - I'd rather Ctrl-Alt-Backspace and fix it.

Anyway, so Karmic (and apparently certain installs before Karmic, as well) uses an init system called "Upstart". If you've tried messing with update-rc and noticed that disabling /etc/init.d/gdm doesn't work, this is why. Oh sure, you can run /etc/init.d/gdm stop, but it's only temporary, assuming that works for you at all - for me it does not - my console does not recover and I get a black screen.

To get it to stop permanently the proper way is apparently to work with upstart. You'll notice some definitions in /etc/init (no, not /etc/init.d). These work somewhat like the Gentoo init.d scripts - you can define dependencies, events, phases, etc. So looking at /etc/init/gdm.conf I see:

Continue reading "Disabling X server autostart (gdm) on Ubuntu Karmic (9.10)"

Linux Upgrading to Ubuntu 9.10 Karmic Koala breaks X (xorg) on intel driver on 945G chipset

Posted by Admin • Monday, November 2. 2009 • Category: Linux
After upgrading my IBM desktop with "82945G/GZ Integrated Graphics Controller" X stopped working entirely, regardless of any changes to xorg.conf. Running startx manually revealed an error like this:

(EE) Failed to load module "i810" (module does not exist, 0)
(EE) open /dev/fb0: No such file or directory
(EE) intel(0): [drm] Failed to open DRM device for : No such file or directory
(EE) intel(0): Failed to become DRM master.


Took me a little while to figure out how to get me my machine back:

Continue reading "Upgrading to Ubuntu 9.10 Karmic Koala breaks X (xorg) on intel driver on 945G chipset"

Linux Backing Up Google Docs automatically from Linux

Posted by Admin • Monday, October 26. 2009 • Category: Linux
I'm not quite sure why a working example of doing this is so hard to find!

As far as I can tell, at the time of this writing there are two choices of ready-made (and free) apps that do this: GDocBackup and php-google-backup, a tiny php script (on google code) that uses Zend libraries. The former is a windows binary and is said to run in Mono. The latter is a php script which currently partially works (can't handle spreadsheets or PDF's). Not wanting to run Mono (an emulator - I might as well write this in Java), and not satisfied with only backing up .doc's and presentations... I hacked up my own.

Here is how I did it

Continue reading "Backing Up Google Docs automatically from Linux"

Linux Getting Pidgin to sign off when you lock your screen

Posted by Admin • Wednesday, October 14. 2009 • Category: Linux
I am signed in to google talk from many places - blackberry, laptops, desktops, etc - and every once in a while, IM's don't go to the right one. Since I lock my workstation at the office whenever I get up, I figured it'd be nice to have Pidgin log off at the same time.

I am not sure how you would do this in Windows, but in Linux (Ubuntu in my case), I did it like this:

Changed my screen lock hotkey (Ctrl-Alt-l for me) to run the following:
xlock -startCmd "purple-remote setstatus?status=offline" -endCmd "purple-remote setstatus?status=available"
That's it. If you want specific screensaver modes you can stick them in them too:
xlock -mode blank -startCmd "purple-remote setstatus?status=offline" -endCmd "purple-remote setstatus?status=available"

Update: July 2012


Ubuntu has a broken version of xlock (1:5.31-1) which gets the BadMatch (invalid parameter attributes) error. I switched to using slock from "suckless-tools" package, like so:
bash -c "purple-remote setstatus?status=offline ; slock ; purple-remote setstatus?status=available"

Interestingly, after running slock, xlock works too.. it's actually related to dpms: If you run xset +dpms, xlock will work (once).
You can adjust the xlock version for this bug as follows:
xlock -mode blank -startCmd "xset +dpms ; purple-remote setstatus?status=offline" -endCmd "purple-remote setstatus?status=available"


PS: Doing this in openbox:


<keybind key="C-A-l">
        <action name="Execute">
                <startupnotify><enabled>true</enabled><name>Run</name></startupnotify>
                <command>xlock -startCmd "purple-remote setstatus?status=offline" -endCmd "purple-remote setstatus?status=available"</command>
        </action>
</keybind>
 

Linux Fixing freezing and no sound youtube and flash on ubuntu

Posted by Admin • Monday, September 28. 2009 • Category: Linux

Problem:


I've had this issue for many months but obviously I don't use flash enough to really figure it out. The first few youtube videos would play, but with no sound. If you seek back and forth, or play sound from another player (eg audacious), you may get skipping sound for a little while. Eventually the whole player stops advancing, though you can still seek.

Solution:


  • You may have installed a dozen version of flash by now. As long as they are all ubuntu packages, you can leave them all installed (or you can remove them all)
  • Install the official release from adobe: Adobe Flash, current version is 10. Pick .deb format for the download.
  • Now run sudo update-alternatives --all
    ... This will ask you for all alternatives there are for your system, but among them there will be 5-10 flash-related questions for each browser (including text browsers, apparently). Pick the newly installed adobe-flashplugin like so:
      There are 2 alternatives which provide `mozilla-flashplugin'.
    
      Selection    Alternative
    -----------------------------------------------
    *+        1    /usr/lib/flashplugin-installer/libflashplayer.so
              2    /usr/lib/adobe-flashplugin/libflashplayer.so
    Press enter to keep the default[*], or type selection number: 2
    
  • Bounce Firefox and you should be all set

    • Software Mixing

      Once I got this fixed up, I now had reliable flash playback with one little problem... There was still no sound half the time - if another audio application grabbed my sound card before firefox (eg rhythmbox). Took me a while to figure out what to search for (usually the biggest issue, right?). Apparently the issue is twofold:
      1. My onboard sound card either doesn't do hardware mixing, or the drivers don't support that
      2. Alsa should have figured that out, and turned on Software Mixing, but for some reason it doesn't do that in Ubuntu
      Once I understood this, I used This page to help me out. Grabbed their ~/.asoundrc, restarted all the audio apps, and all seem to be sharing the sound card peacefully now.