Linux Search & Kill Group of Processes

0 comments


The following quick command can be used to kill one or more processes found using the combination of ps and grep.
ps -ef | grep FooBar | awk '{print $2}' | xargs kill -9

Ruby Error on Require JSON in Ubuntu

0 comments


Received the following error from a Ruby application when it called require 'json'.

irb(main):002:0> require 'rubygems'
=> true
irb(main):004:0> require 'json'
LoadError: no such file to load -- json
from /usr/lib/ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
from /usr/lib/ruby/1.8/rubygems/custom_require.rb:31:in `require'
from (irb):4
from :0
JSON is in the libjson-ruby package. So to fix this
sudo apt-get install libjson-ruby
and presto!
irb(main):001:0> require 'json'
=> true

Linux Argument List Too Long

0 comments

Encountered this cleaning out a directory overflowing with thousands of log files. When entering rm *.log or even a more narrow set such as rm *2011.log, the following error occurs.

sudo: unable to execute /bin/rm: Argument list too long

Solutions
Use find to output the file names one at a time, sending each to the rm (or some other) command.

find /home/username -type f -name "*.log" | xargs rm -f
find /home/username -maxdepth 1 -type f -name "*.log" | xargs rm -f
find $HOME -maxdepth 1 -type f -name "*.log" -exec rm "{}" \;

Django Notes

0 comments

A few tips, tricks, gotcha's, and other findings from working with Django for Python.

Complex Queries

Complex queries are run in Django as "raw" queries. The following information will get you well on your way with complex queries including queries on databases other than the default in a multi-database setup.


  • Multiple databases require Django 1.2+
  • When performing raw queries, the table and column names are the actual names define in the database, not the names modeled in Django.
  • Raw query must include the primary key
  • Use db_manager('mydb') to specify other than the default database.
    Ex: Author.objects.db_manager('mydb').raw('SELECT id, name FROM library_authors WHERE ....')
  • Use cursor for even more complex queries. These can be handled by a class to simplify accessing.
  • Use 2 %'s (%%) when using % in a raw query.
    Ex: "LIKE %foo" ~~> "LIKE %%foo"

References

https://docs.djangoproject.com/en/dev/topics/db/multi-db/#using-raw-cursors-with-multiple-databases
https://docs.djangoproject.com/en/1.3/topics/db/sql/
http://osdir.com/ml/django-users/2010-01/msg01419.html
http://www.djangobook.com/en/2.0/chapter10/
https://docs.djangoproject.com/en/dev/topics/db/queries/#escaping-percent-signs-and-underscores-in-like-statements

Note the warning about passing parameters to raw,
https://docs.djangoproject.com/en/dev/topics/db/sql/#passing-parameters-into-raw

Modeling Existing Tables

When modeling existing tables by default, Django gives each model an "id" field. This can cause an unknown column error if your table does not have an id field. Resolve this by declaring another column as the primary_key.

see:
https://docs.djangoproject.com/en/dev/topics/db/models/#automatic-primary-key-fields

Passing Data to a Template

Troubleshooting

Caught OperationalError while rendering: (1054, "Unknown column 'myTable.id' in 'field list'")

https://docs.djangoproject.com/en/dev/topics/db/models/#automatic-primary-key-fields
must assign a column as primary key so Django does not try to use default 'id'

Cool Quick Linux Tools

0 comments

These cool tools are awesome for tweeking your Linux workflow. Admin multiple machines at the same time, add GUI dialogs to your bash scripts, and more.

In Short: shFlags, xvkbd, xclip, Zenity, cssh, tree

Zenity Date Select Dialog
Let's start with the one utility, shFlags, that would be useful in any shell script. shFlags (Shell Flags) is a terrific library that simplifies handling of command-line flags, parameters, and arguments passed to your script. It aims to be a portable cross shell/OS alternative to getopt. In the tests I've done, shFlags rocks.

xvkbd is the X Virtual Keyboard and, as it sounds, is a virtual keyboard for the X window system. It can be useful for kiosk installations, however you can use its command-line functionality to send commands to X windows from within a script. The script can fill data in a window, nice.

xclip provides a command line interface to the X11 clipboard. Hugh? Without touching the mouse, you can copy data that can be later pasted in X. A script could process some data and put the result in the clipboard for the user. xclip's functionality does not end there, but I will leave that for you to discover.

Zenity, the key to providing GTK dialog boxes for shell scripts. Confirm decisions, get input, show progress all in a nifty GTK dialog called from within the shell script. The short examples on the website obviate how cool Zenity is.

ClusterSSH, available in most Linux repositories or downloadable from Sourceforge, allows you to ssh into and issue commands to multiple machines at the same time. Now making quick modifications on multiple clients is a breeze.

Tree. This seemingly simple command line tool is amazing for displaying your directory structure in a tree format. Visualize and analyze your directory and file structure quickly and easily.

Linux Timezone QuickTip

0 comments

Recently, after moving to a different timezone, I noticed that my automated backup scripts were failing. Why? They were running based on the old timezone (during a disallowed time).

To update to the new timezone, specify the correct timezone in the directory path below:

cd /etc

sudo ln -sf /usr/share/zoneinfo/US/[yourzone] localtime
Issue the date command to see the new date/time/zone.

Logic:
/etc/localtime is a symbolic link to the correct timezone data as stored in /usr/share/zoneinfo.  Directories are also available for other countries within the zoneinfo directory.

Google Tools (I Didn't Know I Was Missing)

0 comments

My Google search results recently returned a couple of Google tools that I hadn't seen listed yet. I occasionally browse the more | even more page in my Google account to see what's new. Here are two tools I haven't seen listed there yet (one very useful, one just for fun).

  • Google Financial Comparison
    Find and compare rates on mortgages, credit cards, CDs, checking and savings accounts.

    Includes a nice overview, side-by-side comparison, and more. And in typical Google style, all without being bombarded with obnoxious advertising like many other bank/financial rating sites.
  • Google Hotpot
    Rate and review places you know, see recommendations from friends and find new places within your profile based on the ratings and reviews you submit.

I Need Big Expensive Software! (Not Really)

0 comments

A recent issue of Database Trends and Applications magazine quoted a Forrester Research study that found 80% of database installations only use 20% of the features provided. My estimation is that this statistic also applies to other software, especially some of the most "popular" used and required on home, school, and office PCs. And this is a large aspect of why open source software should be used, encouraged, and by no means discriminated against in the public arena.

Let's avoid any anti-Windows or anti-Microsoft propaganda or personal preference. Anyone who knows me, already knows my personal preference for Ubuntu Linux anyhow. I'm going to focus briefly on the MS Office suite of applications, because as we know it is the dominant software in this arena.

My wife does things with MS Office at work that would make most people's head spin. She needs and uses the power, APIs, and scripting that it provides. She justifies the $X for her corporate license for Access, Word, Excel, etc. At home, she uses a word processor, rarely, for basic documents and a spreadsheet for rosters with name, address, etc. There is no justifying the expense of MS Office for home. She will occasionally use the old copy of Office97 from our college days, but our primary productivity software is OpenOffice.org. For me, running a Linux desktop, it's always OpenOffice or other open software.

If a corporation decides to buy a corporate license for MS Office or other proprietary productivity software, that's fine by me. When a government spends tax money on licenses for employees who don't use/need the added functionality, it's misuse of resources.

When a public school requires students to use MS Office to read an assignment downloaded from the Internet or as the only format for submitted assignments, there is a problem and an unfair bias toward students who can afford home computers and more over the MS Office software. This irks me. Of course OpenOffice can read/write to MS Office formats, so those "in the know" are OK (most of the time) but the majority of educators do not know this and if they do it is not taught or explained to students.

Teach students fundamentals, not memorized specifics, so that they can rapidly adapt and learn a variety of tools. I have seen countless times educators and students alike turn aside from alternative software options because it's "not the same," "too different," "too hard." The fundamental differences in MS Office and OpenOffice are negligible, and in my opinion, no more difficult to grasp than when MS Office dropped the menu bar and got all decorated with ribbons and bows. Users adapted to the changes due to necessity. It is no more difficult to adapt to another office suite.

The principle of cost vs features vs needed features vs compatibility, should be looked at in all organizations from small to large corporations, schools, governments, churches, and non-profits.

My point in all this is use the software you need for the job your performing and don't force others into your boat when another (potentially free) option will work equally well.

Mounting USB Storage Devices

0 comments

Today I noticed that my USB storage device (thumb drive, usb drive, memory stick; call it what you will) was not mounting when plugged into the PC. Note: I'm currently running Ubuntu 10.10 Maverick Meerkat.

The solution that fixed this was

sudo apt-get install usbmount
It's also good to note that lsusb will list usb devices detected on your system. Here you'll likely see reference to the usb drive although it isn't being mounted.

And for fun, gconf-editor lets you tweek all manner of settings, one of which is the Nautilus applications setting for auto mounting storage devices.


Note:
usbmount has been known to contain a bug that causes the device to mount as root instead of the logged in user, meaning you cannot modify the data. If this is the case usbmount may not be the correct fix for you. You can also try using Disk Utility to unmount/mount the device and see if that works.
     System | Administration | Disk Utility

Removing Partition, Grub, & Fixing MBR

0 comments

Unfortunately had to remove Linux from a dual boot machine today due to compatibility issues (shame on you hardware manufacturers). I wanted to reassign the Linux partition space back into the Windows partition. No problem, right?  Maybe if you do this type of thing regularly and already have the tools at hand. This is the first time I have actually had to remove Linux, a sad day for sure, but a new set of tools for the future. Following is a brief walkthrough. (note: this was complicated by being a Eee PC meaning no CDs, USB memory devices only.)

In Brief:

  • Parted Magic Live USB
    • remove Linux partition
    • wipe MBR from terminal
      dd if=/dev/zero of=/dev/sda bs=446 count=1
  • Windows/Dos Bootable USB
    • xfdisk /MBR


Details of My Steps:


Alternatively:
You should also be able to do roughly the same using the Windows Recovery Console to issue a fixmbr, fixboot, fdisk /MBR, fixboot c:, or bootcfg /rebuild.  In my case I did the above steps while waiting for files to copy to USB so I could access the recovery console. Instructions for getting a USB bootable recovery console can be found at http://www.msfn.org/board/USB-Boot-Recovery-Console-t111986.html although I never completed the steps and cannot confirm their functionality.

Deceptively "open source"

0 comments

Reviewing some software today and saw a link for SupportPRO SupportDesk. Their site leads with the following statement

"SupportPRO SupportDesk is an open source web based Helpdesk system with integrated knowledge base application."
Looking around all I see are links for pricing, demo, order, free trial. No links for download, source, OSI, etc.

There's a live help link, lets ask. During a short discussion I am bluntly informed that open source does not mean free and that the script is not free. Evidently after purchasing the the script they deliver it unencrypted, aka the source is openly readable and modifiable hence their claim to open source.

To me this is deceptive, and their script is sold source editable, not open source in the terms many of us consider. At that, I'm on to evaluate some true open source software.

Bulk Image Resizing

0 comments

Looking for a native tool for bulk manipulation of images on Linux.


Enter two fantastic solutions:

Both are tools that integrate directly into Nautilus and allow you to modify the existing image or save a modified copy.


Nautilus Image Conver provides quick context menu options to resize or rotate and image or group of images.


Phatch likes to work always on a directory of images and provides more advanced editing functions in addition to resizing, such as rounding corners,  adding a background shadow, and watermarking.


Both are fantastic tools!

Windows, Mac, and other non-Linux users don't feel left out. Phatch is actually cross-platform! Still there's something for you too, keep reading the backstory.

While previewing Adobe Air, I tried the Shrink-o-Matic application. I found that I really liked it and the interface was great for clients who like to update their own websites, but don't understand (or want to) how to edit their images to an appropriate size.

After a few simple configurations (setting desired image size and output location), the application is as simple as dragging, dropping, then opening and using your newly resized images. It's worth looking up and trying out if your not a Linux user. (drop me a line and i can send you a step-by-step guide to setting it up.)

My PCs are not the latest and greatest, they are actually more like well aged wine, and they do their jobs very well (with Ubuntu). Running Adobe Air is a bit cumbersome so I wanted a native application that would run fast. That led me to find the great Linux applications listed above, which provide such a vast array of features that I no longer need Shrink-o-Matic (which is still a nice tool) and I can dump Adobe and Air (which makes me happy).

As a side note, I'm also a little biased against Adobe as from experience I fell their sales tactics are deceptive and they misuse/abuse open source and free software. That's not to say all of their end products are bad though.

The Windows7 Experience

0 comments

Some observation from a recent (brief) encounter with Windows 7

  • why does a "restart required" message show up under the win explorer icon in the taskbar? oh yeah, to trick us so we think an app is still running when we restart :D
  • given two windows partially overlapping. was it planned that tool tips for the lower window would appear under the other window? (Gnome's window management works so productively for me that everything else just seems icky. Way to go Gnome team!)
  • window and scroll wheel focus are a real annoyance to me. They just slow me down too much to have to click every window I want to use. (again Gnome gives me max productivity)
After getting used to the feel of Win7 and copping with the inconveniences, I do see some major improvements in the OS. Here's the way I figure.
  • XP added new features/utilities and later quick-added some for security issues
  • These were not bad ideas but lacked in user-interface/interaction
    (they were annoying)
  • Vista fixed many of those so they were not (as) annoying and added other new features/utilities
  • again not bad ideas but lacking in user-interface/interaction
    (again they were annoying)
  • Repeat the same for Windows 7.

The cycle makes some sense in that after enough complaints and feedback it's easy to see a better solution to something. Would be nice though if they received enough feedback from beta testing to clean up the annoyances before resleasing (aka a Windows that stayed out of the way and let me do what I need to do... quickly)

Although I think some of the features and UI changes may actually increase the learning curve for noobs, it is actually not that bad an OS to use.

A few UI things I do like
  • Automatically rotating wallpapers
    (Linux users see Gnome Wallpaper Tray applet)
  • Handling of taskbar icons/applications (for the most part)
    • Ability to show taskbar icons only or icons with labels
      (although the menu to change this setting seems miss-worded)
    • popup previews of application windows
    • application specific options on right-click
    • application window coming to front when hovering over preview
    • curved and colored highligh behind running application icons.
      • color varies by app
      • makes feel more organic
  • show desktop in bottom right that frames all windows and displays desktop
  • Auto versioning / previous versions of files
    (sounds good although i never played with it)
And one item that I have yet to decide if I like or dislike (i'm mixed between, perception, functinality, and reality)
  • multiple tabs in IE (and other tabbed apps) show as multiple windows in taskbar preview. Useful? Confusing? Annoying? Beneficial? I'm still in the air.
    • clicking preview brings up IE and that tab gets focus (I like that)
    • it seems missleading since they are tabs in the same window, especially with IE as it still like to open WAY to many new windows for my liking.
    • although functionally, it seems a productivity booster
It was interesting to see some of the new features and improvements, but it come nowhere near swaying me from Ubuntu Linux and Gnome desktop. Linux is still simply the fastest, most efficient, and enjoyable way for me to work.

Recycling Junk Mail

0 comments

While flipping through the junk mail recently as it headed to the trash can, I noticed that the daily credit card junk mail is going green. Or eco-friendly, or eco-conscious, or whatever. At least that is the impression they would like to give, by adding a small "recycle please", "recyclable", or "please recycle" logo on the back of the envelopes.

Recycling pickup is not free where I live. So these companies, who want my money and to charge huge interest rates for credit also want me to pay to recycle the junk they send me so they can appear more eco-friendly? How about they wasting huge amounts paper and other resources each year to send me these things. Do I really need all the legal details about a credit card I don't want? Try sending me that stack of paper when I express interest in your product, or provide it electronically.

Point is, they are wasteful. Don't make me pay or feel guilty for your waste so that you can improve your eco-image.

Pugs

0 comments

Pugs...

Testing in Safari on Linux

0 comments

Had the need to test Apple's Safari browser on a website or three. Issue: I'm a Linux (Ubuntu) user. Of course Linux is awesome and super good, but the big Apple doesn't make a version of Safari for Linux.

Solution: PlayOnLinux

Looks like it is popular for gaming, but it also has more practical use, it sets up and configures to let me run Safari through Wine. BTW, it also supports Google Chrome (yeah!).

Download it for your distro here.
  http://www.playonlinux.com/en/download.html

Many to choose from with instructions or simply use the available .deb file. Install and launch PlayOnLinux (it appeared in my Games menu).  Click the Install option, select Internet, choose Safari, click Apply, then walk through the screens and your all set. Once installed it will show up in your wine menu and desktop if you chose the desktop option (i had to manually make the desktop launcher executable).

Note while installing Safari: When asked about "Install Bonjour for Windows" and "Apple updates" uncheck both of these, you do not want them as they will cause problems.

Model Railroad

0 comments

Beginnings of a model railroad in the basement. Additional videos over the next week, catch them on YouTube.

Screenshot? Shutter at the Thought

0 comments

Formerly known as GScrot, Shutter is a fantastic screenshot tool for Linux.
In their own words,

Shutter is a feature-rich screenshot program. You can take a screenshot of a specific area, window, your whole screen, or even of a website - apply different effects to it, draw on it to highlight points, and then upload to an image hosting site, all within one window. Shutter is free, open-source, and licensed under GPL v3.
For what it's worth, Shutter comes highly recommended by me. I am currently using it for all my screen capture needs.

Downloads are available for multiple distributions, of course, including Ubuntu. A quick deb install and your all set.

Reorganizing & Merging PDF Files

0 comments

Needed to merge and then reorder the pages several pdf files today. I don't have and prefer not to use Adobe tools when I can avoid them. A quick google turned up a couple of options.

  1. Ghostscript from the command line to merge them
    (would have needed the pages in order first)
  2. PDF-Shuffler GUI
A quick overview on Ghostscript can be found on linux.com.

Since my pages were not necessarily in order, I decided to give PDF-Shuffler a whirl. To give fair credit, I learded of PDF-Shuffler from bigbrovar.

PDF-Shuffler is a small python app packaged in a .deb file for the Debian flavors of Linux, including Ubuntu. Download, install deb, launch app from office menu, drag pdf onto application window. Once the pdf loads you can drag and drop pages to move them around, delete and rotate pages, or drag to add another pdf. When finished export the new pdf.

It's quick, easy, and worked without the slightest problem on my 12-15 files and merged them all into one 10 meg pdf.

California Coaster Train

0 comments

Saw the Coaster in SanDiego; fantastic in real life, great on video, and cool surfliner in small scale. Check it.