December 2009
1 post
Where the parentheses go... (and seq)
I have a dickens of a time remembering how to parenthesize a pipeline of commands so they can be timed as a group. Here’s a snippet I read on the net today (from a post about reducing Python’s memory footprint):
time (for i in $(seq 1 100); do python -c "pass"; done)
So, parentheses around everything to be timed. The seq command work on my Linux box (/usr/bin/seq) but not my...
July 2009
1 post
Better one-liner for ssh keys
Useful update to previous one-liner for adding ssh keys (letter to Linux Journal August 2009). Instead of using ssh and cat, simply use ssh-copy-id. For example:
ssh-copy-id -i id_rsa user@somehost
Will not only append your id_rsa.pub key to authorized_keys on somehost, it will ensure that the permissions on .ssh and authorized_keys are correct.
June 2009
2 posts
Fixing Entourage inbox
My Entourage inbox stopped updating! Everything else (sent items, junk folder, etc.) was updating fine. The lazyweb led me to the following fix: Empty the Inbox cache.
Right-click Inbox folder, select Folder Properties. “Empty Cache” is in the middle of the General pane. Read the warnings, then click Empty.
This empties your inbox folder, which then gets repopulated from the...
A few programmer aphorisms
Seen on a software-architect’s blog:
Think Once — Code Twice
Some thoughts for the day
* "Quick And Dirty == Guaranteed Rework"
* "He Who Codes First Loses"
* "Think Once -- Code Twice"
* "Admin's Law: It's Always Permissions"
* "Programmer's Law: If it's not permissions, it's the path"
* "If it seems hard, you're doing it wrong"
* "One-Off == The First of Many"
* "Requirements...
May 2009
1 post
Nice one-liners from LJ Hack and /
Kyle Rankin writes a column for LInux Journal called Hack and /. He’s got a couple nice ssh-based one-liners in the June 2009 issue, which I’m listing here for myself and others to find later.
Put public key on remote server
This appends your public key to the authorized keys list on the remote server. This saves scp-ing it, ssh-ing, and appending it. Nice.
ssh...
March 2009
1 post
Lightning Talks
Hello from PyCon Lightning Talks. Jehiah will be presenting txLoadBalancer.
February 2009
2 posts
I'm going to Pycon 2009 →
Some PostgreSQL reminders
From Chander Ganesan via email:
/etc/init.d/postgresql reload
This rereads postgresql.conf, and new backend processes get the new settings. Existing backends are unchanged.
alter database db_name set log_min_duration_statement 250;
Immediately causes all backends to log statements taking longer than 250 seconds to run (assuming logging is active already).
alter database db_name reset...
January 2009
5 posts
Saving a couple idioms
Things I’ve written down from articles lately, don’t want to lose them:
Nice awk example (count number of users of each shell):
awk -F: '{x[$7]+=1} END {for(z in x) {print z, x[z]}}' /etc/passwd
Nonobvious (to dumb me, at least) use of slicing in Python:
def reverse(str):
return str[::-1]
print reverse('Bite me')
Using fileinput Python module:
import fileinput
for line...
From Linux Journal letters, a nice way to use text in compressed files without needing to know they’re compressed, or what they’re compress with…
function do_cat()
{
local CAT
CAT=cat
case "$1" in
*.gz) CAT=zcat;;
*.bz2) CAT=bzcat;;
esac
${CAT} "$1"
}
function smart_cat()
{
local i
for i in "$@"; do
do_cat "$i"
done
}
...
"Stealth" error messages
Weird but true: If your Linux disk is full, your XWin-32-based PC xterms won’t connect, complaining of an “authentication error.”
netstat -tpe
From Linux magazine sidebar, nice set of switches for netstat:
netstat -tpe
t limits to TCP, p lists PID, and e gives some nice extra stuff (sendq, recvq, username, inode, foreign address looked up via DNS, program name)
You need to be root for some of these to appear. This is my new favorite invocation of netstat (I used to use -anp routinely).
Oldest file (of my own) in my home directory
If I’m pretending to be a blogger, I should jump on a meme or two. Here’s one (find and post the oldest file in your home directory):
http://rhodesmill.org/brandon/2009/new-years-meme/
Not much earthshaking to find, because I change computers pretty often. This was in a backup from a prior computer:
2002-03-26 ./backups/dhancock_old_dev/oracle/schemas/save/reserved28/xmlrpc.py
...
December 2008
5 posts
Fontcase is Very Nice Indeed!
Fontcase (beta font-viewing) utility is GREAT! Very handsome user interface, for starters, and completely intuitive to use.
I’ve been using Lord Pixel’s UnicodeFontInfo tool, which is nice, but Fontcase seems much easier to get an overview from and then to delve deeper into a particular font.
I got on their beta by signing up on their website. I don’t know how much it will...
Right-click without Ctrl key!
I’ve been doing Ctrl-click on my Macbook Pro to simulate a right-click, but I learned yesterday that you can do this directly on the trackpad: Place two fingers on the pad and click!
Oracle XE reinstallation woes
Argggghhh! After spending most of the day trying to reproduce yesterday’s successful Oracle XE installation, I finally figured out why it wouldn’t work. The shared memory segment for Oracle wasn’t being released (I don’t know why) when the RPM was uninstalled, and each time I installed after that, the startup script refused to create a second instance of XE.
I used ipcs...
See full paths in Finder →
Nice tip from The Ultimate Apple Weblog.
In a terminal window, do:
defaults write com.apple.finder _FXShowPosixPathInTitle -bool YES
Then quit and relaunch the Finder. You’ll start seeing paths in the title bar for Finder windows.
Change password without prompts from command line
I found this while surfing. I think it only works on RedHat Linuxes and their progeny. And of course, you need to be root. This is nice for adding a user and password from a script.
echo 'NewSecretPassword' | passwd --stdin someuser
This sets the password for ‘someuser’ to ‘NewSecretPassword’
November 2008
4 posts
Giving Dropbox a try
2GB free storage, a UI that promises to be easy to use. I’ll update as I try more.
PostgreSQL dump and restore with PostGIS data
Our initial data load from production to test wasn’t complete, and we figured out that we got correct results using a custom format for pg_dump. We don’t have to DEFINE the custom format, just use it. On the other end, you need to use pg_restore to bring that custom format dump into a database.
To dump:
pg_dump -Fc dbname > dbname.dmp
To restore:
pg_restore -Fc -d dbname...
Access to password-protected database without...
Dunno why I never looked this up before. We’ve been using expect or pexpect (Python expect) to provide a password to our PostgreSQL database when we use psql from inside another program. This means that the password is in plain text in the Python module.
Today I learned about a much cleaner way: the ~/.pgpass file. The format is:
host:port:database:username:password
Permissions on the...
Fixing Time Machine backups
Time Machine was failing, always after getting about 450MB copied. This got me worried that I was getting disk errors again. I used Tech Tool Pro (a nice, albeit expensive, upgrade to the Tech Tool Deluxe that comes with Apple Care) to try to fix it. I ran every diagnostic and repair I would while still booted from the main drive. No joy.
Through this all, SuperDuper was happy to keep my...
October 2008
5 posts
Fixing "unable to connect to display"
When I reboot my Macbook Pro, use Terminal to log in to some other system, and then try to display something back to the Macbook, I always get the unable-to-connect error message.
What fixes it is killing X and restarting it (luckily it lives in the Dock).
I wonder if it is a problem with the startup order? But I don’t know how to change that.
Getting rid of old Entourage cached addresses
Posting here to save me time looking for this next time I need it: http://support.microsoft.com/kb/280299
The funny thing is that to delete a cached address, you have to add it to your Contacts, and then delete it.
Helpful aliases for memory usage
These are helpful for those using virtual servers with memory limits. Each one needs to be on one line.
alias memtotal="ps -u $LOGNAME h -o rss | (tr '\n' +; echo 0) | bc"
alias memtotal='ps -u $LOGNAME h -o rss | (tr '\n' +; echo 0) | bc'
alias memhttpd="ps -u $LOGNAME -o pid,rss,command | grep httpd | grep -v grep | awk 'BEGIN {sum=0} {sum=sum+\$2} END {printf(\"%f MB\n\",sum/1024)}'"
...
SQLite is the backend for the Safari cache
Learned something new today: The Safari browser cache is (according to the page I was reading) is an SQLite database. SQLite is absolutely amazing for its tiny, tiny footprint.
Cisco VPN - Fix for Error 51: Unable to... →
The most comprehensive set of things to try when your Mac OS X Cisco VPN gives the error shown in the title.
September 2008
6 posts
p.s. No progress with vim so far
I had to give my beloved Macbook to Apple for repairs (expected to take a week), so I’ve been busy whipping a corporate Windows laptop into usable shape. That’s my excuse for not working with a new editor…
Python startup switch
There’s a nice “-v” startup switch for the Python compiler that I learned the importance of today. We were unable to import a particular module, and the -v switch showed errors like:
# blahblah/FPXMLBuilder.pyc matches blahblah/FPXMLBuilder.py
Fatal Python error: PyString_InternInPlace: strings only please!
Removing the pyc file and reimporting fixed this.
Old dogs vs. new (editor) tricks
I guess I’ll start learning vi (Vim, really), if for no other reason than to prove I’m not too old to learn a new editor. I’d go for Textmate, except I might as well learn something that applies to all the platforms where I work.
Good article debunking most of my (ancient) reasons for avoiding vi: http://www.viemu.com/a-why-vi-vim.html
Got my Entourage-Exchange address lookup working
So for months I’ve been living with Entourage giving me an “error contacting LDAP server” error when I try to look up names on our company’s Exchange server. It turns out the LDAP access followed the Mailbox when it was migrated to a new server, but my Entourage didn’t migrate LDAP.
I found the new LDAP hostname by starting the wizard for adding an Exchange account,...
The watch command (Unix/Linux)
While attending a training class recently, I saw the instructor use the ‘watch’ command. What is does is clear the screen, echo the date/time, and execute the command you pass it. Very nice. For example:
watch ls /usr/local/pgsql/data/pg_xlog
lets you watch that directory for files to appear. If you need to pipe two commands together, put them together in quotes:
watch "ps auxww |...
Instapaper →
Nice tool for saving web pages to read later. Until I found this, I’d been opening pages in Firefox tabs and just hoping I found time to read them before the browser closes (either purposely or crash-osely).
August 2008
3 posts
Disabling the new Emacs splash screen →
What an awful new “feature” in Emacs, but it’s simple to disable in your .emacs file:
(setq inhibit-splash-screen t);
pg_controldata
I found a nice PostgreSQL command the other day: pg_controldata. Takes one argument (the path to the data directory) and returns a whole bunch of useful information about the instance. This’ll be useful for determining how up to date a PostgreSQL warm standby database is. See the line below labeled “Time of latest checkpoint.” There’s other useful information in the...
Finally
After being bugged by jehiah for quite some time (a year or two) I am finally going to start posting some of my thoughts about python (and whatever else comes to mind) here.