Voder-Vocoder

The Log of Hal Canary

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

nocomments

#!/bin/sh
# ~/bin/nocomments
# Remove all '#' commented lines and
# empty lines.  Use stdin and stdout.
# Written 2007 Hal Canary.
# Dedicated to the Public Domain.
grep -v '^\#\|^$' "$@"

Hal Canary | Computers & Code | 2008-08-10 09:31:10 EDT
Permanent Link | No Comments

the diet

People ask what I eat. Here it is:

The Diet:

Breakfast
• 1 quart of iced tea, prepared the night before and allowed to cool to room temperature before adding ice. (I like to start the day hydrated.)
• 1 cup Uncle Sam Cereal, served with non-fat milk, berries (straw-, black-, rasp-, or blue-), and 1 packet of sucralose.

Lunch
• Salad, prepared before work: Spinach or lettuce, cubed smoked turkey lunch-meat, cheese (reduced-fat feta, cheddar, or blue), nuts (pecans, almond slices, sunflower kernels, or peanuts), sometimes berries, and home-made vinaigrette.
• 1/2 cup unsalted peanuts, mixed with half a box of raisins. (I sometimes make this my mid-morning snack, if I have an opportunity.)
• Two reduced-fat low-moisture Mozzarella string cheese sticks.
• 1 quart of iced tea, left over from breakfast.

Mid-afternoon Snack
• 1/2 cup unsalted peanuts, mixed with the other half of the box of raisins.
• Water.

Dinner
• An identical salad, prepared with lunch that morning.
• Water
• 2 cups of low-cal yogurt (if I’m still hungry).

Hal Canary | Food, Life | 2008-08-10 08:06:34 EDT
Permanent Link | No Comments

/etc/sudoers

Because the syntax of the /etc/sudoers file is obscure, I’m noting down here exactly what I’ve done to mine:

root	ALL=(ALL) ALL
%admin ALL=(ALL) ALL
%admin ALL=NOPASSWD: /usr/bin/wodim
%admin ALL=NOPASSWD: /usr/bin/apt-get
%admin ALL=NOPASSWD: /sbin/reboot
%admin ALL=NOPASSWD: /sbin/poweroff

This allows a few commonly used commands to be executed without a password.

Hal Canary | Computers & Code | 2008-08-08 07:46:24 EDT
Permanent Link | No Comments

9 pounds of bacon

“The Deliverator’s car has enough potential energy packed into its batteries to fire a pound of bacon into the Asteroid Belt.”

I did the calculation just now. My 20 gallon gas tank has enough potential energy to put 9 pounds of bacon into the Asteroid Belt.

131 megajoules * 20 / G / ( (mass of sun / 414,703,838 km) - (mass of sun/ 149,597,887.5 km) - (mass of earth / radius of earth)) in pounds

Hal Canary | Physics, Books | 2008-06-15 19:55:07 EDT
Permanent Link | Comments Off

jolietify

#!/usr/bin/env python

# jolietify - reduce a filename to 64 chars, preserving
# the suffix.
#
# See http://en.wikipedia.org/wiki/Joliet_(file_system)
# for a justification.  It is recomended that filenames
# be reduced to 64 chars before putting on a CD-ROM.
#
# 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
import glob
import os
import os.path

def jolietify(dirfilename):
    (head,fname) = os.path.split(dirfilename)
    if (len(fname) <= 64):
        print "Is good:", dirfilename
        return 1
    splitname=fname.rsplit('.',1)
    if (len(splitname) == 1):
	new=os.path.join(head,splitname[0][0:64])
        print 'rename', dirfilename, new
        os.rename(dirfilename, new)
        return 0
    else:
	new=os.path.join(head,
            splitname[0][0:63-len(splitname[1])]+'.'+splitname[1])
	print 'rename', dirfilename, new
        os.rename(dirfilename, new)
        return 0

if __name__ == "__main__":
    for x in sys.argv[1:]:
       for y in glob.glob(x):
            jolietify(y)

Hal Canary | Computers & Code | 2008-06-07 18:11:49 EDT
Permanent Link | Comments Off

~/bin/longest-filename

#!/bin/sh
#DTPD#
# ~/bin/longest-filename
# How long is the longest filename
# in these directories?
{ for x in "$@" ; do
find "$x" -exec basename {} \;
done } | wc -L

Hal Canary | Computers & Code | 2008-06-07 18:10:57 EDT
Permanent Link | Comments Off

Rewrite the tax code!

Rules of the game:

You can change anything you want about the federal tax code, but your changes must be revenue-neutral. No starve-the-beast proposals.

* * *

My suggestion.

–> Let A be the annual income a full-time (40-hour/week) minimum-wage worker would make.

–> Let B be the annual income of the median worker. (50% of Americans make less than him, 50% more.)

–> Let C be the income of the 67-percentile worker. (66.7% of Americans make less than him, 33.3% more.)

Replace current federal taxes with the following:

1) Increase the EITC (earned income tax credit) to a very large level. Make it 0 at zero income, maximum at A, and get down to 0 again at B.

2) Income tax of 50% on all income greater than C, minus philanthropic donations.

3) A huge tax on carbon emissions. On the order of $10 per gallon of gasoline, with an carbon-equivalent tax on coal, diesel, natural gas, etc.

4) A general policy that negative externalities are taxed equal to the indirect cost to society. Carbon emissions are the biggest part of this at the moment, but I like the idea of pollution taxes greater than the cost of totally cleaning up the pollution. And a big tax on non-reusable goods.

* * *

UPDATE: Hey, there’s a website for revenue-neutral carbon taxes!

Hal Canary | Energy Policy, Economics, Politics | 2008-05-30 07:18:21 EDT
Permanent Link | Comments Off

Razor

Saw today that Battlestar Galactica “Razor” was nominated for the 2008 Hugo for Best Dramatic Presentation, Short Form. I wouldn’t call a 104 minute film “short,” even if the abridged version premired on TV before it was released on DVD. I also noticed that I still hadn’t watched it, even though the Netflix DVD was sitting on my desk.

So I watched it. Four nested flashbacks. Yeah, I’d vote for it, were I a voter. Although I did like “Blink.”

Hal Canary | TV, Movies | 2008-03-24 21:48:02 EDT
Permanent Link | Comments Off

ibii+

[Thumb] Ibises

[Thumb] Black-crowned Night Heron

[Thumb]

[Thumb]

[Thumb]

[Thumb]

[Thumb]

[Thumb]

Hal Canary | Photos | 2008-02-13 11:47:41 EST
Permanent Link | Comments Off

Random password generator

#!/usr/bin/env python

# Randoms - 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 Tkinter
import os
import base64

def genrandint():
    'Generates a random integer between 0 and (2^32)-1'
    x = 0
    for i in range(4):
        x = (x << 8)+ord(os.urandom(1))
    return x

def randstring():
    'generate a 142-bit password consisting of A-Za-z0-9'
    return base64.b64encode(os.urandom(18),'Zz')

def genrand128int():
    'Generates a random integer between 0 and (2^128)-1'
    x = 0
    for i in range(16):
        x = (x << 8)+ord(os.urandom(1))
    return x

def generaterandletts():
    'generate a 131-bit password consisting of a-z'
    s = ''
    for i in range(28):
        x = ''
        while x == '' :
            y = ord(os.urandom(1)) # 0-255
            if y < (256//26*26):
                x = chr((y % 26) + 97)
        s = s + x
        if i%4 == 3:
            s = s + ' '
    return s

class Application(Tkinter.Frame):
    'a window that displays text'
    def __init__(self, master=None):
        Tkinter.Frame.__init__(self, master)
        self.grid()
        self.createWidgets()
        self.winfo_toplevel().resizable(width=False, height=False)

    def createWidgets(self):
        self.textBox = Tkinter.Text(self,height=4,padx=5, pady=5)
        self.textBox.grid()
        self.textBox.configure(state='disabled')
        self.quitButton = Tkinter.Button(self, text="Quit", command=self.quit)
        self.quitButton.grid()        

    def addText(self, pos, string):
        self.textBox.configure(state='normal')
        self.textBox.insert (pos, string)
        self.textBox.configure(state='disabled')        

app = Application()
app.master.title('Randomness')
app.addText('1.0', 'Integer: %d\n' % genrandint())
app.addText('2.0', 'Integer: %d\n' % genrand128int())
app.addText('3.0', 'String: %s\n' % randstring())
app.addText('4.0', 'String: %s' % generaterandletts())
app.mainloop()

Compiled version for windows

Hal Canary | Computers & Code | 2008-02-03 23:56:27 EST
Permanent Link | Comments Off

zipme.py

#!/usr/bin/env python

# zipme.py - 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.

# To use me:
#   >>> from zipme import zipme
#   >>> zipme('directoryname')

import zipfile
import os
import os.path
def zipdir(z,x):
    if os.path.isfile(x):
        z.write(x)
        print 'wrote %s' % x
    elif os.path.isdir(x):
        for y in os.listdir(x):
            zipdir(z,x + os.sep + y)
    else:
        print 'ERROR: %s' % x

def zipme(d):
    z = zipfile.ZipFile(d+'.zip','w',zipfile.ZIP_DEFLATED)
    zipdir(z,d)
    z.close()

if __name__ == "__main__":
    zipme('Randoms')

Hal Canary | Computers & Code | 2008-01-28 21:49:48 EST
Permanent Link | Comments Off

genpasswd.py

#!/usr/bin/env python
# ~/bin/genpasswd.py
#   Generate a random password with about
#   142 bits of randomness, making use of
#   /dev/urandom.
# Note:
#   Most online services have somewhat
#   arbitrary rules about what characters
#   can be included in a password. So we
#   limit ourselves to A-Za-z0-9.
# Copyright 2007-2008 Hal Canary
# Dedicated to the Public Domain.
import os, base64
print base64.b64encode(os.urandom(18),'Zz')

Hal Canary | Computers & Code | 2008-01-27 15:54:05 EST
Permanent Link | Comments Off

« Previous Entries |

Copyright 1997-2007 by Hal Canary.
mailto: h3 at halcanary dot org
xmpp:halcanary@jabber.org
aim:halwcanary
http://halcanary.org