Thursday, October 1, 2009

Is Lazy Dead?

Check out islazydead.com for the most recent answer to the question: Is Lazy Dead?
BEGIN:VCARD
VERSION:3.0
N:;;;;
item1.ADR;type=HOME;type=pref:;;13101-13225 Old Bayleaf Rd;Wake Forest;North Carolina;27587;United States
item1.X-ABADR:us
item2.URL;type=pref:http\://maps.google.com/maps?f=q&q=35.972862\,-78.631057%20%2813101-13225%20Old%20Bayleaf%20Rd\,%20Wake%20Forest\,%20NC%2027587\,%20USA%29
item2.X-ABLabel:map url
END:VCARD


Nostalgic: Enough with the nostalgic posting!

I'll quit it with the nostalgic postings. I found a CGI written in C that I used for tracking my shirts in Google's cache here and a ton of stuff in general stored in Google's cache from when it indexed tun0.net.

Nostalgic: Wrote this when I was 15 and very bored

#define p(r, s, t, u) printf( "%s%s%s%s\n",r,s,t,u)
typedef char b;b E[]="\E[2J";b B[]="__\n \\ ).( `\n '( v )"
;b A[]=" @@@\n @. .@\n @\\=/@\n .- -.\n /(.|.)\\";main
(){b C[]="\n \\ ).( /\n '( v )`";b D[]="\n \\|/\n (|)\n"
" '-`\n";for(;; ){p(E,A,C, D);sleep(1);p(E,A,B,D);sleep(1);}}

Nostalgic: Encode DVD Rips

There are now a lot of easy ways to encode DVDs on Linux. I don't even use Linux much any more, and on OS X I'd just use Handbrake. Anyway, this is a script I used to use:

#!/bin/sh

# NAME
# xcode.sh
#
# DESCRIPTION
# Encode a [concatenated] VOB file into an MPEG4/MP3 video
# using mencoder (a la mplayer) and create a lower quality
# video for iPods using ffmpeg.
#
# The reason I wrote this was because I had a bunch of VOBs
# and concatenated them together. Then I decided, "Hey, it's
# OK to lose some quality to gain more disk space!"
#
# DEPENDENCIES
# * mplayer (transcode VOBs to AVI)
# * ffmpeg (transcode to iPod supported format)
# * vobcopy (optional - to rip VOBs from movie DVD)
#
# KNOWN BUGS
# * Requires the user to rip the DVD manually using vobcopy
# or similar application and manually concatenate the
# appropriate VOB files into 1 big VOB which this script
# then will transcode.
# * The output video may be too large for a single 700MB CD.
# * The output video is not the proper format (h.264/aac)
# for a Video iPod.
# * Command line options parsing and features are pathetic.
# * Doesn't handle cropping at all (no -vf cropdetect, etc.)
#
# USAGE
# you can use mplayer to dump a dvd title
# # mplayer dvd://1 -dumpstream -dumpfile title1.vob
#
# or, you can rip the whole dvd with vobcopy
# # mount -o ro /dev/dvd /mnt
# # cd ~/dvd && vobcopy -I /mnt -m
#
# determine which VOBs you want and concatenate them
# # cat VTS_01_[1-8].xVOB > movie.vob
#
# ensure xcode.sh is configured right (srcdir and outdir)
# # vi xcode.sh
#
# run it to process fullscreen (4:3) video (-w for 16:9)
# # xcode.sh -f movie
#
# LICENSE
# Public domain. Distribute freely.
#
# This script is provided "as is" and comes with no warranty
# whatsoever. Any liability and responsibility is hereby
# fully disclaimed. Use at your own risk.
#

#################################################################
#
# STATIC CONFIGURATION
#
#################################################################

# where to find VOB
srcdir="/mnt/media/dvdrip"
# if you uncomment the following, find comment out line 100, also
#srcdir="`pwd`"

# here to dump the products
outdir="/home/packetjunkie/movies"

# 16:9 (widescreen)
widescale="640:360"

# 4:3 (fullscreen)
fullscale="640:480"

# default
scale=$widescale

# video bitrate
vbr="700"

# logfile
log="${outdir}/xcode.log"


#################################################################
#
# SETTINGS DETERMINED AT RUN TIME
#
#################################################################

# aspect ratio?
if [ "x$2" != "x" ] ; then
if [ "$1" = "-w" ] ; then scale=$widescale; shift; fi
if [ "$1" = "-f" ] ; then scale=$fullscale; shift; fi
fi

# movie?
if [ "x$1" = "x" ] ; then echo "Usage: $0 [-w|-f] <movie>"; exit 1; fi
movie="$1"
srcdir="${srcdir}/${movie}"
echo "[`date +"%F %T"`] $movie - scale = $scale - $srcdir" >> "$log"

# determine path information based on settings
vob="${srcdir}/${movie}.vob"
avi="${outdir}/${movie}.avi"
pod="${outdir}/${movie}.mp4"

tmp="${outdir}/${movie}.vob.avi"
snd="${outdir}/${movie}.snd.avi"
prv="${outdir}/${movie}.prv.avi"


#################################################################
#
# DO THE ACTUAL WORK
#
#################################################################

# fix broken index
echo "[`date +"%F %T"`] $movie - fixing index" >> "$log"
mencoder "${vob}" -o "${tmp}" -ovc copy -oac copy

# encode audio
echo "[`date +"%F %T"`] $movie - encoding audio" >> "$log"
mencoder "${tmp}" -ovc frameno -o "${snd}" \
-oac mp3lame \
-lameopts abr:br=128 \
-alang en

# pass 1
echo "[`date +"%F %T"`] $movie - pass 1" >> "$log"
mencoder -oac copy -o /dev/null \
-ovc lavc \
-lavcopts vcodec=mpeg4:vbitrate=$vbr:vhq:vpass=1 \
-vf scale=$scale \
-ss 0:20 -endpos 0:30 \
"${tmp}"

# pass 2
echo "[`date +"%F %T"`] $movie - pass 2" >> "$log"
mencoder -oac copy -o "${prv}" \
-ovc lavc \
-lavcopts vcodec=mpeg4:vbitrate=$vbr:vhq:vpass=2 \
-vf scale=$scale \
-ss 0:20 -endpos 0:30 \
"${tmp}"

# final
echo "[`date +"%F %T"`] $movie - fully transcoding" >> "$log"
mencoder -oac copy -o /dev/null \
-ovc lavc \
-lavcopts vcodec=mpeg4:vbitrate=$vbr:vhq:vpass=1:vqmin=2:vqmax=31 \
-vf scale=$scale \
"${tmp}"
mencoder -oac copy -o "${avi}" \
-ovc lavc \
-lavcopts vcodec=mpeg4:vbitrate=$vbr:vhq:vpass=2:vqmin=2:vqmax=31 \
-vf scale=$scale \
"${tmp}"

# clean
echo "[`date +"%F %T"`] $movie - cleaning" >> "$log"
rm -f "${tmp}" "${snd}" "${prv}"
rm -f divx2pass.log

# ipod
echo "[`date +"%F %T"`] $movie - making ipod mpeg4" >> "$log"

# reduced resolution for ipod
if [ "$scale" = "640:480" ] ; then
podscale="320x240"
aspect="4:3"
else
podscale="320x180"
aspect="16:9"
fi

# process it
ffmpeg -i "${avi}" -f mp4 -vcodec mpeg4 \
-maxrate 1000 -b 700 -qmin 3 -qmax 5 -bufsize 4096 -g 300 \
-acodec aac -ab 192 -s $podscale -aspect $aspect "${pod}"

# done
(echo "[`date +"%F %T"`] $movie - finished";echo) >> "$log"

Nostalgic: SSL Certification Checker

While digging up old stuff I found a C program for checking if a SSL certificate is expired.

#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <netdb.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <sys/types.h>
#include <sys/uio.h>
#include <unistd.h>
#include <openssl/crypto.h>
#include <openssl/x509.h>
#include <openssl/pem.h>
#include <openssl/ssl.h>
#include <openssl/err.h>

#define HOSTNAME "example.com"

int main() {
int sock; /* socket descriptor */
struct hostent *hp; /* for resolving host */
struct servent *sp; /* for resolving port */
struct sockaddr_in sin; /* for creating socket */
SSL *ssl; /* for ssl ;) */
SSL_CTX *ctx; /* context for ssl */
SSL_METHOD *(*ssl_method)() = SSLv23_client_method;
X509 *cert; /* certificate we hope to get */
char certinfo[2048]; /* store output of program */

/* resolve the hostname and verify the port (should be 443) */
hp = gethostbyname(HOSTNAME);
sp = getservbyname("https", "tcp");

/* create a socket */
bzero((char*)&sin, sizeof(sin));
sin.sin_family = AF_INET;
bcopy(hp->h_addr,(char*)&sin.sin_addr, hp->h_length);
sin.sin_port = sp->s_port;
sock = socket(AF_INET, SOCK_STREAM, 0);

/* connect */
printf("connecting to %s\n", HOSTNAME);
connect(sock, (struct sockaddr*)&sin, sizeof(sin));

/* openssl voodoo */
SSL_library_init();
SSL_load_error_strings();
ctx = SSL_CTX_new(ssl_method());
ssl = SSL_new(ctx);
SSL_set_fd(ssl, sock);
SSL_connect(ssl);
cert = NULL;

/* pull up the server's certificate */
cert = SSL_get_peer_certificate(ssl);

/* if we have a certificate continue */
if(cert != NULL) {
char buf[256], *p;

/* certinfo will be the output of the program */
strncpy(certinfo, "\nsubject:", sizeof(certinfo));

/* store the x509 info in buf */
X509_NAME_oneline(X509_get_subject_name(cert), buf, sizeof(buf));

/* tokenize the string we got above which is delimited by '/' */
p = strtok(buf, "/");
while(p != NULL) {
/* add everything to certinfo, which we'll dump in the end,
* and try to make certinfo look pretty
* */
strncat(certinfo, "\n\t", sizeof(certinfo));
strncat(certinfo, p, sizeof(certinfo));
/* continue tokenizing until end of string */
p = strtok(NULL, "/");
}

/* this is essentially the same as above except instead of the cert's
* subject data we're now working with the issuer data
*/
strncat(certinfo, "\nissuer:", sizeof(certinfo));
X509_NAME_oneline(X509_get_issuer_name(cert), buf, sizeof(buf));
p = strtok(buf, "/");
while(p != NULL) {
strncat(certinfo, "\n\t", sizeof(certinfo));
strncat(certinfo, p, sizeof(certinfo));
p = strtok(NULL, "/");
}
strncat(certinfo, "\n", sizeof(certinfo));

/* expiration check */
if(X509_cmp_current_time (X509_get_notBefore (cert)) >= 0)
strncat(certinfo, "certificate is not yet valid\n", sizeof(certinfo));
else if(X509_cmp_current_time (X509_get_notAfter (cert)) <= 0)
strncat(certinfo, "certficate has already expired\n", sizeof(certinfo));
else
strncat(certinfo, "certificate expiration is valid\n", sizeof(certinfo));

/* finally dump the info */
printf("%s", certinfo);
}
/* if getting the certificate failed */
else {
printf("couldn't pull certificate.\ntoo lazy to include debugging info.\nsorry.\n");
}

return 0;
}


I didn't bother testing it, but I bet it would still work. (Requires openssl libraries to compile.)

Nostalgic: Old Gaim Plugin

I feel a bit nostalgic right now. I was Googling myself (name, usernames, email addresses) and one of the things I found was a Gaim plugin I'd written years ago. Considering Gaim renamed itself to Pidgin in April 2007, that's an indication of how old this plugin is. It would probably require an entire rewrite to work with libpurple and Pidgin now. Anyway here's the old code:

This is Google's cache of http://tun0.net/misc/trash/gaim-random-away/gaim-random-away-0.1/random-away.c. It is a snapshot of the page as it appeared on Aug 22, 2009 18:31:57 GMT. The current page could have changed in the meantime. Learn more

Text-only version
These search terms are highlighted: thisemailaddress gmail com

/*
* Gaim Random Away Plugin
* V. Hari
* ========================================
*
* Read the COPYING file for license information.
* Read the README file for general information.
*
*/

#include "internal.h"
#include "debug.h"
#include "plugin.h"
#include "version.h"
#include "gtkgaim.h"
#include "signals.h"
#include "away.h"
#include "gtkblist.h"

#include
#include

#define RAWAY_PLUGIN "random-away"
#define RAWAY_VERSION "0.1"

static GaimPlugin *raway_plugin = NULL;

static int
raway_away_foo(void)
{
GSList *l;
const char *away_name = "You Are (Fight Club)";
guint i, n;

n = ((guint)rand() % g_slist_length(away_messages))+1;

for(l = away_messages, i = 1; l; l = l->next)
{
//if(strcmp(away_name, ((struct away_message *)l->data)->name))
if(i++ == n)
{
do_away_message(NULL, l->data);
break;
}
}

return TRUE;
}

static int
raway_make_menu(void)
{
GtkWidget *menuitem;

gaim_debug(GAIM_DEBUG_INFO, RAWAY_PLUGIN, "random-away creating menu\n");
gaim_separator(awaymenu);
menuitem = gtk_menu_item_new_with_label(_("Random Away"));
gtk_menu_shell_append(GTK_MENU_SHELL(awaymenu), menuitem);
g_signal_connect(G_OBJECT(menuitem), "activate",
G_CALLBACK(raway_away_foo), NULL);
gtk_widget_show(menuitem);

return TRUE;
}

static void
signed_on_cb(GaimConnection *gc, void *data)
{
raway_make_menu();
}


static gboolean
plugin_load(GaimPlugin *plugin)
{
void *conn_handle = gaim_connections_get_handle();

gaim_debug(GAIM_DEBUG_INFO, RAWAY_PLUGIN, "random-away plugin loaded.\n");

srand(time(NULL));

gaim_signal_connect(conn_handle, "signed-on", plugin,
GAIM_CALLBACK(signed_on_cb), NULL);

return TRUE;
}

static gboolean
plugin_unload(GaimPlugin *plugin)
{
gaim_debug(GAIM_DEBUG_INFO, RAWAY_PLUGIN, "random-away plugin unloaded.\n");

return TRUE;
}

static GaimPluginInfo info =
{
GAIM_PLUGIN_MAGIC,
GAIM_MAJOR_VERSION,
GAIM_MINOR_VERSION,
GAIM_PLUGIN_STANDARD,
NULL,
0,
NULL,
GAIM_PRIORITY_DEFAULT,
NULL,
N_("Random Away Plugin"),
RAWAY_VERSION,
N_("Set a random away message."),
N_("Set a random away message."),
"V. Hari ",
"http://packetjunkie.net/",
plugin_load,
plugin_unload,
NULL,
NULL,
NULL,
NULL,
NULL
};

static void
init_plugin(GaimPlugin *plugin)
{
}

GAIM_INIT_PLUGIN(random-away, init_plugin, info)

States I've driven through

I've driven through the following states. (This list does not count taking a train through/to or flying to as a destination or layover - only driving through with me as the driver.)

Alabama, Arkansas, Colorado, Delaware,
Florida, Georgia, Illinois, Indiana,
Iowa, Kansas, Kentucky, Louisiana,
Maryland, Missippi, Missouri, Nebraska,
New Jersey, New York, North Carolina, Pennsylvania,
South Carolina, Tennessee, Texas, Utah,
Virginia, West Virginia, Wyoming

Feeding a scared stray