Categories: geek » linux

RSS - Atom - Subscribe via email

Extracting the xinput device number instead of hardcoding it

Posted: - Modified: | geek, linux

I've been using my wireless mouse more often these days. XWindows detected it fine and it works without a hitch, hooray! The downside is that as an additional input device, it threw my xinput device numbering off, so the script I was using to rotate the stylus input along with the screen on my tablet PC stopped working. Easy enough to fix by extracting the device number from the output of xinput using the cut command.

The relevant changes were:

xsetwacom set $(xinput | grep eraser | cut -c 55-56) rotate $direction
xsetwacom set $(xinput | grep touch | cut -c 55-56) rotate $direction
xsetwacom set $(xinput | grep stylus | cut -c 55-56) rotate $direction

My rotate-screen script on GitHub

Calibre and Qt 5.5

| geek, linux

A recent apt-get dist-upgrade resulted in the removal of calibre and calibre-bin from my system. I've been using Calibre to convert e-books from HTML and EPUB (some developer references, some fanfiction =) ) and copy them onto my Kindle.

It turned out that the Calibre packaged in Ubuntu required qtbase-abi-5-4-2 and my recent dist-upgrade installed Qt 5.5. I needed to upgrade to Calibre 2.49, which wasn't available on any of the PPAs I checked (despite instructions to the contrary).

Installing Calibre from the Calibre website made it work, though. In fact, the Calibre website says:

Please do not use your distribution provided calibre package, as those are often buggy/outdated. Instead use the Binary install described below.

I wasn't too keen on piping the output of a wget command to sudo , but a quick scan of the script didn't turn up anything suspicious. Anyway, now I can convert EPUBs to MOBIs and easily copy them onto my Kindle, yay!

Trying out dual-booting Linux again

| geek, linux

After a long, long time being on Windows because of Autodesk Sketchbook Pro – keeping sane with a mishmash of Cygwin and Linux virtual boxes so that I could get around the limits of Windows as a development platform, and grumbling about little things like the slow performance of git and the occasional problem with too-long file paths – I’m giving dual-booting to Linux a try again.

W-‘s good influence here: his new SSD arrived and he decided to allocate some space for dual-booting to Linux. Since we have the same hardware configuration for our laptops, I figured I’d see if the Wacom drivers Just Worked and if the sketching programs on Linux had improved since I last checked them out. Mypaint still didn’t have the selection tools I was looking for, but Krita looks like it might work for my sketches. The interface isn’t as pen-friendly as Autodesk Sketchbook Pro (which I couldn’t get going under WINE), but I might be able to get the hang of using the subset of features I actually rely on.

I had some setup issues in the beginning. The Kubuntu 15 install disk I tried crashed during setup due to a wireless-related issue. I tried ElementaryOS, but found it to be a hassle because the default Elementary theme caused Emacs to crash. (Priorities, priorities.) Frankensteining it back to a basic Ubuntu distribution by removing packages and editing files like /etc/lsb-release didn’t completely solve my problems, so I installed Kubuntu 14 instead. That seems to be working so far.

I ran into a few more issues with applications. Dropbox sync created directories but not the files within them. I’m not sure whether it was the fiddling we did with our network setup (including quite a few reboots of routers and modems) or whether Dropbox sync got fixed after I unlinked my laptop through the web interface and then reconfigured it, but at least my files are downloading now at a decent speed.

The version of Evernote I installed under WINE didn’t allow me to edit notes. Upgrading WINE to 1.7 and downgrading Evernote to 5.8.3 seems to have made Evernote work, though, so now it’s synchronizing the gazillions of notes I’ve accumulated throughout the years.

Postfix Gmail forwarding was straightforward to set up. I successfully sent a test message, and my Gnus config seems to be working fine with direct IMAP access to Gmail. I might give offlineimap a try, maybe with notmuch.

I have an old Truecrypt volume lying around, and the Linux binaries were able to mount it. Hooray!

Git was giving me problems, so I added the git-core repository.

I’ll still probably need to boot into Windows to do my business accounting in Quickbooks, which I use mainly because it imports into Turbotax and therefore saves me from having to figure out all the tax stuff by hand. I don’t do that frequently, though, so it should be okay.

I use a Python script to download Flickr metadata. Turns out the latest version of flickrapi is incompatible with it, so I downgraded flickrapi with:

sudo pip install flickrapi==1.4.5

and that worked.

It turns out it’s the little things you notice. I missed being able to use Win+number to start or switch to applications. Fortunately, the following script worked for me, once I figured out that KDE’s custom keyboard shortcuts wanted full path to the shell command: /home/sacha/bin/focus_or_launch emacs instead of using ~/bin/focus_or_launch emacs. I modified it slightly to only look at –class instead of –name.

#!/bin/bash

# NAME:         focus_or_launch
# VERSION:      0.4
# AUTHOR:       (c) 2014 Glutanimate <https://github.com/Glutanimate/>
#
# DESCRIPTION:  Focus existing app window or launch application if no
#               window found
#
#               Simplified version of a script by Henning Bekel
#               (https://bbs.archlinux.org/viewtopic.php?pid=625009#p625009)
#
# DEPENDENCIES: xdotool
#
# LICENSE:      GNU GPLv3 (http://www.gnu.de/documents/gpl-3.0.en.html)
#
# NOTICE:       THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. 
#               EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 
#               PROVIDE THE PROGRAM “AS IS” WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR 
#               IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 
#               AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND 
#               PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE,
#               YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
#
#               IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY 
#               COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS 
#               PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, 
#               INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE 
#               THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED 
#               INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE 
#               PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER 
#               PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
#
# USAGE:        focus_or_launch <command>
# EXAMPLE:      focus_or_launch google-chrome


############# GLOBVAR/PREP ###############

Executable="$1"
ExecutableBase="$(basename "$Executable")"
Usage="\
Usage: $(basename $0) command
E.g.:  $(basename $0) google-chrome\
"

############## USGCHECKS #################

if [[ $# -ne 1 || "$1" =~ ^(-h|--help)$ ]]; then
  echo "$Usage"
  exit 1
fi

################ MAIN ####################

MostRecentWID="$(xdotool search --class "$ExecutableBase" | tail -1 2> /dev/null)"

if [[ -z "$MostRecentWID" ]]; then
  echo "$ExecutableBase not found. Launching new window."
  "$Executable" > /dev/null 2>&1 &
  disown
else
  echo "Focusing existing instance of $ExecutableBase."
  # use brute-force approach if activating most recent WID doesn't work
  xdotool windowactivate "$MostRecentWID" 2>&1 | grep failed \
  && xdotool search --class "$ExecutableBase" windowactivate %@
fi

There are probably a few more things I’ll run into, but it’s a good start. =)

Setting up dynamic DNS with Tomato and Namecheap, and limiting SSH

Posted: - Modified: | geek, linux

We have a computer downstairs with backups of files, and I’ve been using it to explore Vagrant and development using virtual machines as well. It can be useful to be able to SSH into it from outside our network, so I spent some time setting up a dynamic domain name, port forwarding, and new limits for the SSH server.

Namecheap (the domain name registrar that I use) supports dynamic domains, so it was easy to enable.

  1. Enable dynamic domains: Manage Domains, choose the domain, and then choose Dynamic DNS. Enable it and copy the password.
  2. Create an A record: Choose All Records and add a subdomain with a temporary address (ex: 127.0.0.1) and type A. Save the settings.

Our router uses the Tomato firmware, which has built-in support for Namecheap and other dynamic DNS provider.

  1. Click on BasicDDNS.
  2. Fill in the details for Dynamic DNS 1.

Before I forwarded the ports, I wanted to make sure that SSH permitted password authentication on our local network but required passphrases for external connections. OpenSSH: requiring keys, but allow passwords from some locations (Michael W. Lucas) was really helpful. I edited /etc/ssh/sshd_config, set PasswordAuthentication no, and added the following lines to the end of the file:

Match Address 192.168.0.0/16
  PasswordAuthentication yes

(I had some problems in the beginning because I typed this as Yes instead of yes… Case matters!)

I restarted the SSH server with service ssh restart and confirmed that I could still SSH in.

Back to Tomato. Port Forwarding lets you set up forwarding rules. The port for SSH is 22, so I filled in a row with the port I wanted, the internal port, and the internal IP address of the server. I clicked Save (forgot to do this a few times because the button was near the end of the page) and that was that.

On Windows, I walked W- through generating a DSA public key with PuttyGEN, loading it in Pageant, and copying it to his .ssh/authorized_keys2 file.

Posting this here because I’m probably going to want to do this again someday, and it took some searching around. Besides, someone might find it handy!

Working with FTP sites

Posted: - Modified: | geek, linux

One of the Drupal sites I’m working on is on a web host that allows only FTP access, not SSH or SCP access. I set up a local development environment so that I can play around without affecting the integration or production site. This also lets me use drush to do a group upgrade of modules without downloading and installing them one by one. But without the convenience of rsync over ssh, how can I easily transfer my updated code to the server?

lftp is a free Linux/UNIX tool for working with files over FTP. Packages are available on major distros, so installing it as easy as apt-get install lftp or working with your distro’s package manager. To start an lftp session, type lftp user@host. It supports the usual FTP commands, but it also has a few nifty additions. For example, here are some commands I use often:

lftp mirror somedirectory :: Recursively copy somedirectory from the remote computer to the local computer lftp mirror -R somedirectory :: Recursively copy somedirectory from your local computer to the remote computer lftp mirror -R somedirectory destination :: Recursively copy somedirectory to destination – saves me a lot of cd and lcd-ing lftp mirror -R --dry-run somedirectory :: Don’t actually copy somedirectory; print out the commands that would have been run

It’s smart enough to transfer only files that have changed, which is much better than having to remember and copy them. It can also use parallel connections for extra speed.

Type help at the lftp command prompt to find out more, or check out the lftp webpage. Hope this saves you time!

Electronic ears: Using Performous to learn how to sing

Posted: - Modified: | kaizen, life, linux

SCHEDULED: 2010-07-28 Wed 08:00

I've been singing in the wrong key(s) all my life. Thanks to Brendon Robinson's recommendation of Performous (a free, open source music application), I can finally work on fixing that.

Part of learning how to sing is getting used to what the notes feel like. I find it difficult to listen to piano notes and figure out if I'm singing at the right pitch. Sometimes I'm sharp, sometimes I'm flat, sometimes I'm way off. Recording is a hassle, and it takes too long between trying something and getting feedback. (I'm amazed by how my dad taught himself all sorts of photography techniques with a film camera…)

Performous provides instant feedback on the musical note and frequency it hears. I can watch the note and slide up and down the scale until I find the right pitch, and I can make up my own exercises for getting the notes right.

https://sachachua.com/blog/wp-content/uploads/2010/07/Performous_20100727T1826564.png

When I can sing scales and vocalizations without a hitch, then I can find a singing teacher to help me with volume and technique. First things first: gotta do it right before I do it loud. =)

I only wish I thought of looking for something like this a long time ago!

*Performous (http://performous.org)*: Free and open source – Microsoft Windows, Mac OS X, Linux

Using supervisord for Nginx+FastCGI+PHP

Posted: - Modified: | geek, linux

I was having problems with spawn-fcgi-standalone occasionally resulting in dead PHP processes, which caused 502 Bad Gateway errors on my site. Crontabbing an /etc/init.d/init-fastcgi start didn't help much, so I looked for other ways to do it. Supervisord looked promising.

Here’s how to get Supervisord:

apt-get install python-setuptools
easy_install supervisor

 

Here’s what to add to /etc/supervisord.conf:

[fcgi-program:php5-cgi]
socket=tcp://127.0.0.1:9000
command=/usr/bin/php5-cgi
numprocs=5
priority=999
process_name=%(program_name)s_%(process_num)02d
user=www-data
autorestart=true
autostart=true
startsecs=1
startretries=3
stopsignal=QUIT
stopwaitsecs=10
redirect_stderr=true
stdout_logfile=/var/log/php5-cgi.log
stdout_logfile_maxbytes=10MB

So far, so good. When I kill the php process, supervisord starts it back up. Progress!

supervisord doesn’t come with an init.d script, but you can get one for Ubuntu.