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

Archive for 2007-03

txt2prehtml

#!/bin/sh
# txt2prehtml
# Copyright 2006-2007 Hal Canary
# DTPD
echo -n '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01
Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type"
  content="text/html; charset=utf-8">
<title> </title>
</head>
<body>
<pre>' ;
fold -w 70 -s "$@" | sed 's/\&/\&amp;/g;
s/\"/\&quot;/g;
s/</\&lt;/g;
s/>/\&gt;/g;
s/\\/\&\#0092;/g;' ;
echo '</pre>
</body>
</html>';

Hal Canary | Computers & Code | 2007-03-28 09:11:21 EDT
Permanent Link | Comments Off

makecdrfiles

Some years ago, cdrecord gained the ability to convert .wav files to an audio CD on the fly. No more messing around with sox! But I’ve found that it’s better to feed files through sox anyways, just to make sure that the file format is correct and the sampling rate is correct:

#!/bin/sh

# makecdrfiles - Convert mp3s to
# .cdr format for an audio CD.
# Copyright 2000-2007 Hal Canary
# Dedicated to the Public Domain.

if [ "$#" -lt 1 ] ; then
  echo "  Useage: $0 file.mp3 [more files.mp3]"
  echo ""
  echo "  After you're done, burn with:"
  echo -n '   sudo cdrecord -v -dao -eject dev=$DEV'
  echo ' -pad -audio *.cdr'
  exit 1
fi
for FILE in "$@" ; do
  nice lame --decode "$FILE" - | \
    nice sox -t wav - "$(basename $FILE .mp3).cdr"
done

I burnt four coasters today before I figured this out.

Hal Canary | Computers & Code | 2007-03-23 11:52:20 EDT
Permanent Link | Comments Off

timeinmicroseconds.c

I wrote this today as a demonstration of where /dev/random gets all its randomness.

/* Copyright 2007 Hal Canary, http://halcanary.org/
Dedicated to the Public Domain. */
#include <stdio.h>
#include <sys/time.h>
int main(void) {
        struct timeval x;
        struct timezone t;
        gettimeofday(&x, &t);
        printf("%u.%06u\n",x.tv_sec,x.tv_usec);
        return(0);
}

And then…

$ cc -o timeinmicroseconds timeinmicroseconds.c
$ while read -s -n 1 x ; do ./timeinmicroseconds ; done

Hal Canary | Computers & Code | 2007-03-22 15:50:15 EDT
Permanent Link | Comments Off

randpassphrase

/*
   randpassphrase.c
   This makes use of /dev/random
   Copyright 2006 Hal Canary
   DTPD (Dedicated to the Public Domain)
   cc -o randpassphrase randpassphrase.c
*/
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main() {
  FILE *devrandom;
  char source [] = "/dev/random";
  unsigned int num;
  if ((devrandom = fopen(source, "rb")) == NULL) {
    fprintf(stderr, "Cannot open %s\n", source);
    exit(EXIT_FAILURE);
  }
  int i;
  for (i=0; i< 28; i++) {
    if (fread(&num, sizeof(num), 1, devrandom) != 1) {
      fprintf(stderr, "%s: file read error.\n", source);
      exit(EXIT_FAILURE);
    }
    printf("%c",((num % 26) + 97));
    fflush(stdout);
    if (i%4 == 3) { printf(" "); }
  }
  close(devrandom);
  printf("\n");
  return(0);
}

Hal Canary | Computers & Code | 2007-03-20 13:24:02 EDT
Permanent Link | Comments Off

hexer

/*  hexer - Convert  binary files to hexadecimal
    Copyright 2007 Hal Canary
    Dedicated to the Public Domain. */
/*  cc -o hexer hexer.c */
#include <stdio.h>
#include <stdlib.h>
int main (int argc, char *argv[]) {
  int i=0;
  char x;
  while (fread(&x, sizeof(x), 1, stdin) == 1) {
    i++;
    printf("%02hhx",x);
    if (i % 32 == 0) {
      printf("\n");
    }
  }
  printf("\n");
  return(0);
}
/*EOF*/

Or:

#!/bin/sh
exec hexdump -e '32/1 "%02x" "\n"' "$@"

Hal Canary | Computers & Code | 2007-03-11 10:16:41 EDT
Permanent Link | Comments Off

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