Voder-Vocoder

The Log of Hal Canary

Navigation: Home | THE LOG | Log Archives | Resume | Contact Info | Public Key | SSL | Math Applets | Site Map | RSS2 | Atom | Backend

Archive for the “Computers & Code” Category

« Previous Entries Next Entries »

Mplayer and Gnome’s screensaver.

#!/bin/sh
#DTPD
gnome-screensaver-command --inhibit &
INHIBIT_PID=$!
mplayer -dvd-device /dev/scd0 -ontop \
	-fs dvdnav:// -nocache 2> /dev/null
kill $INHIBIT_PID

This is how to use gnome-screensaver’s inhibit command with a video player such as mplayer.

Hal Canary | Computers & Code | 2010-02-17 21:05:06 UTC
Permanent Link |
Comments Off (but feel free to email)

time-wasting methods.

/* verbose java masturbation: */
public class Foo {
  private int foobar;
  public void setFoobar(int value) {
    foobar = value;
  }
  public int getFoobar(){
    return foobar;
  }
}
/* much less annoying: */
public class Foo {
  public int foobar;
}

Hal Canary | Computers & Code | 2010-01-17 22:23:38 UTC
Permanent Link |
Comments Off (but feel free to email)

Printing a text file

Printing a text file is one of those basic things you never think about. Unless you are me. I like to play with the variables and make that printout look good.

#!/bin/sh
# Print a UTF-8 document to the default printer
# Written by Hal Canary 2009-12-23.
#DTPD# Dedicated to the Public Domain.

# Configurable Options
font="Monospace 11"
#font="Serif 11"
#font="Sans 11"
paper="letter"
b_margin=0.25
t_margin=0.25
r_margin=0.25
l_margin=0.75

# convert inches to PostScript points
b_margin=`echo "( $b_margin * 72 ) / 1" | bc`
t_margin=`echo "( $t_margin * 72 ) / 1" | bc`
r_margin=`echo "( $r_margin * 72 ) / 1" | bc`
l_margin=`echo "( $l_margin * 72 ) / 1" | bc`

exec paps --font="$font" \
  --paper="$paper" \
  --bottom-margin=$b_margin \
  --top-margin=$t_margin \
  --right-margin=$r_margin \
  --left-margin=$l_margin \
  "$@" | lpr
#EOF#

Hal Canary | Computers & Code | 2010-01-07 13:22:40 UTC
Permanent Link |
Comments Off (but feel free to email)

sed in place

#!/bin/sh
SEDCMD="$1"
shift
for x in "$@" ; do
  dirt=`dirname "${x}"`
  tmp=`mktemp "${dirt}/tmp.XXXXXXXXXX"`
  sed "${SEDCMD}" < "${x}" > "${tmp}"
  mv "${tmp}" "${x}"
  echo "$x fixed."
done

UPDATE: The next day I realized that

sed -i

does exactly the same thing.

Hal Canary | Computers & Code | 2009-11-29 00:45:32 UTC
Permanent Link |
Comments Off (but feel free to email)

Email Advice:

I’ve spent a lot of time writing email the past few weeks, so this is on my mind.

1) Keep your work email separate from personal. People change jobs, your friends shouldn’t lose track of you because of this.

2) Don’t use the email account that comes with your ISP subscription. The next time you move or change ISP you will be forced to get a new email account. Combined with (1), this leaves two options: pay for a hosted email solution, maybe with a personal domain-name, or use one of the free email providers. I suggest Google’s gmail.com, which offers IMAP connection so that you can check you mail using your favorite email client (Mozilla Thunderbird, Apple’s Mail.app, Novell Evolution, Microsoft Outlook, Novell GroupWise, et cetera) as well as on the web.

3) Configure your email client to send plain-text email by default. This usually produces much smaller message sizes and can easily be read by the most email clients.

4) When replying to a email, delete most of the quoted message, leaving only enough to give your reply context. At the very least, delete the signature.

5) If you are not replying to something in a previous message, don’t hit reply; instead, compose a new message. This makes a new thread in clients that organize mails into threads.

6) Don’t top post.

7) If you are going to compose your message in a word processor before sending it, copy-and-paste it into the email’s body instead of sending an attachment.

8) If you must send an attachment, use an open file format.

9) This is one I am very guilty of. If you don’t have time to compose a proper reply to an email that requires a reply, you should shoot off a quick acknowledgement message.

10) If you are at all technically savvy, go ahead and install GnuPG (if your system didn’t already have it) and configure your email client to make use of it to sign your emails.

Hal Canary | Computers & Code, Life | 2009-09-27 22:08:01 UTC
Permanent Link |
Comments Off (but feel free to email)

software for ubuntu

If you are a LTS user like me and stuck on Hardy Heron, sometimes packages are availible that have the newest shiniest thing prepackaged for you. Emacs 23 can be installed with a simple

sudo apt-get install emacs-snapshot-gtk

and then I wrote a little script to launch emacs with my favorite font:

#!/bin/sh
exec emacs-snapshot \
  -fn "Monospace-11" "$@" 

* * *

Another bleeding-edge thing to check out is Google Chrome’s native Linux edition. Go get it from this page.

Hal Canary | Computers & Code | 2009-09-27 22:01:37 UTC
Permanent Link |
Comments Off (but feel free to email)

Command-line Package Tools

Command-line package commands for Debian and Ubuntu-type systems that you should know:

apt-get update
resynchronize the package index files
apt-get dist-upgrade
install the newest versions of all packages currently installed and handle changing dependencies
apt-get install PKG
install a package and figure out dependancies
apt-get remove PKG
remove a package
apt-get clean
clear out the local repository of retrieved package files
apt-cache showpkg PKG
displays information about the package
apt-cache search REGEX
search all available package lists for a regex pattern
dpkg-query --list PATTERN
list installed packages matching given pattern
dpkg-query --status PKG
report the status of specified package
dpkg-query --listfiles PKG
list files installed to your system from a package
dpkg-query --search FILENAME
search for a filename from installed packages
sudo dpkg --install DEBPKGFILE
install a .deb package

Hal Canary | Computers & Code | 2009-09-26 18:54:45 UTC
Permanent Link |
Comments Off (but feel free to email)

ssh-show-key-fingerprint

#!/bin/sh
## ~/bin/ssh-show-key-fingerprint
## Prints out SSHD Key Fingerprints
## Written 2004-2009 Hal Canary
## Dedicated ott he Public Domain.
test "$#" -eq 0 && \
  exec "$0" /etc/ssh/ssh_host_*_key.pub
for file in "$@" ; do
  ( cd `dirname "$file"`;
    /usr/bin/ssh-keygen -l \
      -f  `basename "$file"`; )
done

What to do with this info? first of all, print out the fingerprints and put them in your wallet.

Here’s another thing I do:

ssh-show-key-fingerprint | \
  sudo tee -a /etc/issue.ssh > /dev/null
echo 'Banner /etc/issue.ssh' | \
  sudo tee -a /etc/ssh/sshd_config > /dev/null

This, of course, is in no way a secure way to check your fingerprint, since it is just as vulnerable to a man-in-the-middle attack. But it works as a backup plan.

And some legal theories say you should insert these additional lines into your /ets/issue.ssh file:

 UNAUTHORIZED ACCESS PROHIBITED.

 USE OF THIS SYSTEM BY ANY USER, AUTHORIZED OR UNAUTHORIZED,
 CONSTITUTES CONSENT TO THIS MONITORING, INTERCEPTION,
 RECORDING, READING, COPYING, or CAPTURING and DISCLOSURE
 by SYSTEM OWNER.

Hal Canary | Computers & Code | 2009-09-26 13:01:31 UTC
Permanent Link |
Comments Off (but feel free to email)

MakeBookmarksFile

#!/usr/bin/env python
# MakeBookmarksFile - convert a text file containing
# URLs into a HTMl file with clickable links.
#
# Copyright 2008 Hal Canary
#
# Permission is hereby granted, free of charge, to any
# person obtaining a copy of this software and
# associated documentation files (the 'Software'), to
# deal in the Software without restriction, including
# without limitation the rights to use, copy, modify,
# merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom
# the Software is furnished to do so, subject to the
# following conditions:
#
# The above copyright notice and this permission notice
# shall be included in all copies or substantial
# portions of the Software.
#
# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF
# ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
# LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO
# EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
# ARISING FROM, OUT OF OR IN CONNECTION WITH THE
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

import sys,re
fi = sys.stdin
fo = sys.stdout
s=fi.readline().strip()
## The first line of the input is a title.
head='<!DOCTYPE html PUBLIC \
"-//W3C//DTD HTML 4.01//EN" \
"http://www.w3.org/TR/html4/strict.dtd">\n\
<html><head>\n<meta http-equiv="Content-Type" \
content="text/html; charset=utf-8">\n\
<title>%s</title>\n</head><body><div>\n\
<h1>%s</h1>\n'
fo.write(head % (s,s))
for line in fi:
  s=line.strip()
  if (s == "") :
    continue
  ## convert & to &amp; and so on.
  s=re.sub('&','&amp;',s)
  s=re.sub('<','&lt;',s)
  s=re.sub('>','&gt;',s)
  s=re.sub('"','&quot;',s)
  fo.write("<a href=\"%s\">%s</a><br>\n" % (s,s))
fo.write('</div></body></html>\n')

Hal Canary | Computers & Code | 2009-09-24 12:51:50 UTC
Permanent Link |
Comments Off (but feel free to email)

netbook network mp3 player

I wanted to access my desktop's music library from my living room and play it through the amplifier and speakers there. So I grabbed my netbook, and after fumbling around with NFS for too long, I just tried:

yum install sshfs

(It's a OLPC XO-1, so it's Redhat-based.) And then wrote a little script:

#!/bin/sh
## ~/bin/mount-music
mkdir -p "${HOME}/music"
sshfs hal@sloop:/d/music "${HOME}/music"

I installed mpg123-alsa (by the simple expedient of copying the executable) and wrote a little script to run it.

#!/bin/sh
test -f "${HOME}/music/index.txt" || \
    sshfs hal@sloop:/d/music "${HOME}/music"
cd "${HOME}/music"
exec mpg123-alsa --control --long-tag \
    --shuffle --list index.txt

And index.txt is a file created with the find command on the server:

#!/bin/sh
# run this script to refresh the index file.
cd $HOME/music
find . -type f -a -name '*.mp3' > index.txt

Hal Canary | Computers & Code, Music | 2009-09-16 15:37:59 UTC
Permanent Link |
Comments Off (but feel free to email)

Setting the Gnome Desktop Background With a Script

#!/bin/sh
## Written 2009 Hal Canary
## based on numerous examples
## DTPD
if [ "$#" -lt 1 ] ; then
   X=`basename "$0"`
   echo "Useage:  $X FILENAME"
   exit 1
fi
D=`dirname "$1"`
B=`basename "$1"`
cd $D
X=`pwd`/$B
cd -
if [ ! -f "$X" ] ; then
  echo "not a file: '$X'."
  exit 1
fi
echo "New background: '$X'"
gconftool-2 -t str --set \
  /desktop/gnome/background/picture_filename \
  "$X"
gconftool-2 -t str --set \
  /desktop/gnome/background/picture_options \
  "centered"
exit 0

Hal Canary | Computers & Code | 2009-09-10 18:23:48 UTC
Permanent Link |
Comments Off (but feel free to email)

gain

Back on the CD-ripping project. For popular music, the album titles and artists names are easy and the online databases almost always give me the right answer. But for classical music, there are always discrepancies. So I always change the artist field to be Composer, Performers.

After ripping a few CDs with Sound Juicer, I then run mp3gain (sudo apt-get install --yes mp3gain) on the album.

#!/bin/sh
## ~/bin/mp3gain-a-directory
## Written 2009 Hal Canary, #DTPD#
renice 10 $$ > /dev/null
for dir in "$@" ; do
  if [ ! -d "${dir}" ] ; then
    echo "'${dir}' is not a directory" >&2
  else
    if ( /bin/ls "${dir}/"*.mp3 > /dev/null 2>&1 ) ; then
      /usr/bin/mp3gain -k -a "${dir}/"*.mp3
    else
      echo "'${dir}' has no .mp3 files in it." >&2
    fi
  fi
done

That little script takes a list of directories as arguments, treats all of the mp3 files in a directory as an album and applies the same gain (-a) to each mp3 file in the directory. The -k tells it “of course I don’t want to clip the sound; don’t ask me every time.” Since this operation is processor- and I/O-intensive, the renice is always appreciated.

Or, if I want to all of the directories at once, I can run this command:

find "${HOME}/Music/CDs" -type d -exec mp3gain-a-directory "{}" \;

mp3gain is nice in that it notices that it’s already modified a mp3 and won’t waste time on it again.

Hal Canary | Computers & Code, Music | 2009-08-29 09:49:02 UTC
Permanent Link |
Comments Off (but feel free to email)

« Previous Entries Next Entries »

Copyright 1997-2012 by Hal Canary.
mailto: halcanary at gmail dot com
http://halcanary.org