Monday, December 17, 2012

PAM: a simple RGB+ALPHA file format

To create images with transparencies without too much scaffolding, use the netpgm-associated format PAM, and then use pamtotiff.
#include 

int main() {
    
    printf("P7\n");
    printf("WIDTH 256\n");
    printf("HEIGHT 256\n");
    printf("DEPTH 4\n");
    printf("MAXVAL 255\n");
    printf("TUPLTYPE RGB_ALPHA\n");
    printf("ENDHDR\n");

    unsigned int row,col;
    for (row=0; row<256; row++) {
    for (col=0; col<256; col++) {
        
        printf("%c", (char)col);         // RED
        printf("%c", (char)(255-col));   // GREEN
        printf("%c", (char)row);         // BLUE
        printf("%c", (char)(255-row));   // OPACITY

    }}
    
    return 0;

}

Tuesday, November 20, 2012

Changing the location specified by java.io.tmpdir before running a Java program

On some systems, java.io.tmpdir is hard-coded to /tmp/. This can be changed with, e.g.:
export _JAVA_OPTIONS=-Djava.io.tmpdir=/mnt/tmp/whatever

Wednesday, September 5, 2012

Change a running process to nohup

  1. put the process in the background (CTRL-Z)
  2. make sure it's still running though (bg)
  3. run disown -h

This doesn't really change to nohup, but it does prevent the job from receiving the SIGHUP signal when you exit the shell. Use the -a option to affect all jobs.

According to http://linux.about.com/library/cmd/blcmdl1_disown.htm:

disown [-ar] [-h] [jobspec ...]
    Without options, each jobspec is removed from the table of active jobs. If the -h option is given, each jobspec is not removed from the table, but is marked so that SIGHUP is not sent to the job if the shell receives a SIGHUP. If no jobspec is present, and neither the -a nor the -r option is supplied, the current job is used. If no jobspec is supplied, the -a option means to remove or mark all jobs; the -r option without a jobspec argument restricts operation to running jobs. The return value is 0 unless a jobspec does not specify a valid job.

Thursday, August 16, 2012

Sending attachments from a command line with uuencode

The arguments to uuencode are the file, and the name of the file as it appears in the attachment. I would usually use the same string so I don't have to remember the order.
uuencode file.jpg file.jpg | mail -s 'subject' keith@foosball.com

Wednesday, May 9, 2012

Using GnuPG (gpg) for simple file encryption

How to use GnuPG for simple cases.
  1. Install gpg, e.g.,
    sudo port install gnupg
  2. Create a public/private key for yourself, e.g.,
    gpg --gen-key
    (you will have to answer some questions, I used 'knoto' as my comment
  3. Encrypt a file, e.g.,
    gpg -e -r knoto myfile.foo
    (creates myfile.foo.gpg that can only be decrypted by knoto).

Tuesday, March 20, 2012

vim editing a remote file

Using scp:

vim scp://keith@linux.cs.wmu.edu//home/keith/my.file

You may have to re-enter your password each time you save the file. From http://tipotheday.com/2008/06/08/editing-remote-files-with-vim-and-scp

Thursday, February 2, 2012

Aggregate functions in LaTeX

\usepackage{amsmath} % for underset

\newcommand{\aggregate}[2]{\underset{#2}{\operatornamewithlimits{#1\ }}}


\begin{equation}
x^{*}=\aggregate{argmax}{x\in\mathbf{\mathcal{X}}} f(x)-g(x)
\label{foo.eq}
\end{equation}



Looks like:

Friday, January 13, 2012

Setting up ssh/http port mapping on a Mac using Airport (Extreme)

  1. Find your computer's MAC address
    • Airport utility
    • Advanced section
    • Logging & statistics tab
    • Click on "Logs & statistics" button
    • DHCP clients section
  2. Ensure that DHCP IP address stays the same.
    • Airport utility
    • Internet section
    • DHCP
    • Add a DHCP reservation
      • Description: e.g., Norple@10.0.1.2
      • Reserve by MAC (not client—it's not working for me)
      • I used 10.0.1.2, a fine IP address indeed
  3. Set up port services
    • Airport utility
    • Advanced
    • Port Mapping
    • Add:
      1. SSH (choose nonstandard public port, like 2319, private can be 22)
      2. Person web sharing
      3. Others...?
  4. Update Airport so that it shuts down and restarts
  5. Set up web and file sharing on your computer
    • System preferences
    • Sharing
    • Check remote login, web sharing, whatever you want.

Followers