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

spiral

cat > spiral.ps <<EOF
%!
300 300 translate newpath 3 0 2 copy moveto 604 {
5 add exch 1.01 mul exch 2 copy cos mul 3 copy pop
sin mul lineto } repeat stroke showpage
EOF

Hal Canary | Uncategorized | 2013-06-11 14:00:34 UTC
Permanent Link | No Comments

packages

Bash user? Be sure to install and use the package bash-completion.

Write a lot of code? Don’t forget source-highlight

# add to .bashrc
if command -v source-highlight > /dev/null ; then
source-highlight-less() {
    [ $# -eq 0 ] && { echo "args?" >&2; return 1; }
    for FILE ; do
        if [ -f "$FILE" ] ; then
            source-highlight -i "$FILE" -fesc
        else
            echo "${FILE} does not exist" >&2
        fi
    done | less -R -x${TAB:-8}
}
source_to_html() {
    [ $# -eq 0 ] && { echo "args?" >&2; return 1; }
    for FILE ; do
        if [ -f "$FILE" ] ; then
            source-highlight -i "$FILE" -fhtml-css
        else
            echo "${FILE} does not exist" >&2
        fi
    done | expand -t ${TAB:-8}
}
fi

Hal Canary | Computers & Code | 2013-05-23 13:53:49 UTC
Permanent Link | No Comments

VTKViewer

Hal Canary | Uncategorized | 2013-04-27 14:30:21 UTC
Permanent Link | Comments Off

Surface Viewing

In the class I am sitting in on this semester – Visual Solid Shape, we use a piece of software called shapemonger.

I wanted to get a better view at monge patch (a surface defined by (x,y,f(x,y)) so I wrote a little Python-VTK program to generate a vtkPolyData of the surface.

#!/usr/bin/vtkpython
import vtk

function = lambda x,y: x**2 - y**2
outputName = '/tmp/monge.vtp'
resolution = 50
xmin, xmax = -1.0, 1.0
ymin, ymax = -1.0, 1.0

######
polyData = vtk.vtkPolyData()
points = vtk.vtkPoints()
index = 0
cells = vtk.vtkCellArray()
def makeQuad(cells,a,b,c,d):
    cells.InsertNextCell(4)
    cells.InsertCellPoint(a)
    cells.InsertCellPoint(b)
    cells.InsertCellPoint(c)
    cells.InsertCellPoint(d)
for i in xrange(resolution):
    x = xmin + (xmax-xmin) * i / float(resolution - 1)
    for j in xrange(resolution):
        y = ymin + (ymax - ymin) * j / float(resolution - 1)
        points.InsertPoint(index, x,y,function(x,y))
        if (i > 0) and (j > 0):
            makeQuad(
                cells,index,index-resolution,
                index-resolution-1,index-1)
        index += 1
polyData.SetPoints(points)
polyData.SetPolys(cells)
writer = vtk.vtkXMLPolyDataWriter()
writer.SetInput(polyData)
writer.SetFileName(outputName)
writer.Write()
print 'wrote to', outputName

The surface can be viewed in Paraview or vtkviewer.
[]
To make this surface look better, calculate the normals. The (unnormalized) normal direction is (-∂f/∂x,-∂f/∂y,1).

.......
def partial(func,v,i):
    epsilon = 5e-7
    def f(v,i,d):
        return v[:i] + [v[i] + d] + v[(i+1):]
    return ( (1.0 / 12.0) * func(*f(v,i,-2*epsilon)) +
             (-2.0 / 3.0) * func(*f(v,i,-1*epsilon)) +
             ( 2.0 / 3.0) * func(*f(v,i,+1*epsilon)) +
             (-1.0 /12.0) * func(*f(v,i,+2*epsilon))
              ) / epsilon
def makenormal(func,x,y):
    n = 045;partial(func,[x,y],0),-partial(func,[x,y],1),1.0)
    f = 1.0 / math.sqrt(sum(x**2 for x in n))
    return tuple(f * x for x in n)
.......
normals = vtk.vtkDoubleArray()
normals.SetNumberOfComponents(3)
normals.SetNumberOfTuples(resolution**2)
.......
        .......
        normals.InsertTupleValue(index, makenormal(function,x,y))
        .......
.......
polyData.GetPointData().SetNormals(normals)
.......

[]

Hal Canary | Computer Science, Computers & Code | 2013-04-20 20:00:26 UTC
Permanent Link | Comments Off

reading

Hal Canary | Uncategorized | 2012-08-23 11:32:34 UTC
Permanent Link | Comments Off

Legislative Procedure Via Git

Each member of a legislature has a set of public git repositories; each repository is a proposed law. A legislator can “vote” for any commit in one of his or someone else’s repos by digitally signing the commit’s hash. As soon as a particular version of a law (in the form of a particular commit) has 50%+1 of the legislator’s signatures, it is passed.

Why do I want this? git blame.

Hal Canary | Politics | 2012-08-10 21:17:58 UTC
Permanent Link | Comments Off

taxes

Re Six Policies Economists Love And Politicians Hate:

I’ve been saying things like this for some time. My only caveat is that it is important to keep both the income tax and the earned income tax credit to keep the system progressive. If the consumption tax is high enough, we could limit the income/payroll tax to income above what the median earner makes.

Hal Canary | Economics | 2012-07-20 10:23:43 UTC
Permanent Link | Comments Off

EMRATIO

[emratio]

Hal Canary | Economics, Politics | 2012-07-10 06:50:02 UTC
Permanent Link | Comments Off

POSIX #!/bin/sh

When writing shell scripts to be executed on Linux, Unix, or Mac OS, one can target bash or tcsh. I always reccomend targeting the standard Bourne Shell, since it is guaranteed to exist on POSIX-compatable systems. Unforntunately, a lot of bash-specific documentation exists. So we can go to the source for shell standard: the Single UNIX Specification, The Standard Command Language Interpreter and The Shell Command Language.

Update: here’s a list of all the shell utilities POSIX requires to exist:
admin alias ar asa at awk basename batch bc bg break c99 cal cat cd cflow chgrp chmod chown cksum cmp : comm command compress continue cp crontab csplit ctags cut cxref date dd delta df diff dirname dot du echo ed env eval ex exec exit expand export expr false fc fg file find fold fort77 fuser gencat get getconf getopts grep hash head iconv id ipcrm ipcs jobs join kill lex link ln locale localedef logger logname lp ls m4 mailx make man mesg mkdir mkfifo more mv newgrp nice nl nm nohup od paste patch pathchk pax pr printf prs ps pwd qalter qdel qhold qmove qmsg qrerun qrls qselect qsig qstat qsub read readonly renice return rm rmdel rmdir sact sccs sed set sh shift sleep sort split strings strip stty tabs tail talk tee test time times touch tput tr trap true tsort tty type ulimit umask unalias uname uncompress unexpand unget uniq unlink unset uucp uudecode uuencode uustat uux val vi wait wc what who write xargs yacc zcat

Of these utilities, on my Ubuntu 12.04 system:

Shell builtin or keyword (bash):
: alias bg break cd command continue echo eval exec exit export false fc fg getopts hash jobs kill printf pwd read readonly return set shift test time times trap true type ulimit umask unalias unset wait

Located in /bin or /usr/bin
ar at awk basename batch bc c99 cal cat chgrp chmod chown cksum cmp comm cp crontab csplit ctags cut date dd df diff dirname dot du ed env ex expand expr file find fold fuser gencat getconf head iconv id ipcrm ipcs join link ln locale localedef logger logname lp m4 make man mesg mkdir mkfifo more mv newgrp nice nl nm nohup od paste patch pathchk pr ps renice rm rmdir sed sh sleep sort split strings strip stty tabs tail tee touch tput tr tsort tty uname uncompress unexpand uniq unlink vi wc who write xargs zcat

Not found:
admin asa cflow compress cxref delta fort77 get lex mailx pax prs qalter qdel qhold qmove qmsg qrerun qrls qselect qsig qstat qsub rmdel sact sccs talk unget uucp uudecode uuencode uustat uux val what yacc

dash (/bin/sh) has a smaller set of builtins: it lacks fc and time. /usr/bin/time exists, but there is no fc in dash.

Hal Canary | Computers & Code | 2012-06-19 06:30:49 UTC
Permanent Link | Comments Off

A new printer with Ubuntu 12.04

We have a WiFi network printer in the house: a Kodak ESP C315. The most recent version of Ubuntu (Ubuntu 12.04 Precise) does not recognize it and it asks for a PPD file. This is because the printer-driver-c2esp package is at version 23.1 but version 24 provides that file.

To install:

Get the necesary packages:

$ sudo /usr/bin/apt-get --yes install \
    build-essential cups libcups2-dev \
    libcupsimage2-dev libcupsdriver1-dev

Go to http://sourceforge.net/projects/cupsdriverkodak/files/ and get the file c2esp24.tar.gz .

$ cd `mktemp -d`
$ tar --extract --gzip --file ((...path to...))/c2esp24.tar.gz
$ cd c2esp24/
$ make
$ find . -iname \*.ppd

Copy the apropriate PPD file to /usr/local/share/ppd/

$ sudo mkdir /usr/local/share/ppd
$ sudo cp ppd/Kodak_ESP_C31x_Series.ppd /usr/local/share/ppd/
$ system-config-printer

Then enter /usr/local/share/ppd/Kodak_ESP_C31x_Series.ppd where the CUPS configuration program asks for a PPD file.

Hal Canary | Computers & Code | 2012-06-16 15:44:45 UTC
Permanent Link | Comments Off

generic viewer

#!/bin/sh
#${HOME}/bin/v
#
# Copyright 2012 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.
#
for arg in "$@"; do
  case "${arg##*.}" in
  png|jpg|jpeg|gif|bmp|tif|tiff|tga|targa)
    { /usr/bin/gthumb "$arg" > /dev/null 2>&1 & } ;;
  pdf|ps|eps)
    { /usr/bin/evince "$arg" > /dev/null 2>&1 & } ;;
  txt|tex|c|cxx|cpp|h|hh|cc|C|py|pl|java|hpp|hxx)
    { /usr/bin/emacs "$arg" \
        --eval '(setq buffer-read-only t)' \
        > /dev/null 2>&1 & } ;;
  htm|html)
    full=`readlink --canonicalize "$arg"`
    { /usr/bin/google-chrome "file://${full}" \
        > /dev/null 2>&1 & } ;;
  doc|docx|rtf|odt|odf|odp|ppt|ods|csv|tsv|xls)
    { /usr/bin/ooffice "$arg" > /dev/null 2>&1 & } ;;
  xcf)
    { /usr/bin/gimp "$arg" > /dev/null 2>&1 & } ;;
  svg)
    { /usr/bin/inkscape "$arg" > /dev/null 2>&1 & } ;;
  *)
    echo "What do I do with \"$arg\"?";;
  esac
done

Hal Canary | Computers & Code | 2012-02-24 08:38:00 UTC
Permanent Link | Comments Off

Arcosanti

Hal Canary | Uncategorized | 2012-01-08 17:55:55 UTC
Permanent Link | Comments Off

« Previous Entries |

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