Skip to content

Instantly share code, notes, and snippets.

# the tags' href is in the form "mm.dd.yy Un-URI-encoded File Title.mp3"
MP3_basename = %r{([^/]+)\.mp3$}
res = doc.css("a").collect do |node|
begin
href = node['href']
title = MP3_basename.match(href)[1].sub(/^(\d\d)\.(\d\d)\.\d\d /,'\1-\2 ')
node['href'] = "%s/%s" % [BASEHREF, href]
node.inner_html = Nokogiri::HTML.fragment(title) # to HTML-encode
CAVEAT
------
These notes should apply equally, with little to no modification, to
both Ubuntu and Debian systems.
================================================================================
#!/bin/sh
if [ -z "$1" ]; then
echo "Usage: $(basename $0) debfile_containing_fonts.deb"
exit 2
fi
DEB=$1
if tar --version|grep bsd >/dev/null; then
@penryu
penryu / zshrc.sh
Created September 22, 2010 04:07
# .zshrc fragment
setopt prompt_subst
autoload -Uz vcs_info
if vcs_info 2> /dev/null; then
zstyle ':vcs_info:*' disable cdv darcs mtn p4 svk tla
zstyle ':vcs_info:*' actionformats " [%s:b|%a]"
zstyle ':vcs_info:*' formats " [%s:%b]"
zstyle ':vcs_info:cvs:*' formats " [%s:%r]"
@penryu
penryu / gist:658742
Created November 1, 2010 19:52
output of smartctl(8) on an external WD USB HDD
kane:~>% sudo smartctl --all -T permissive /dev/sdb < 12:50:30
smartctl version 5.38 [x86_64-unknown-linux-gnu] Copyright (C) 2002-8 Bruce Allen
Home page is http://smartmontools.sourceforge.net/
Device: WD 5000BEV External Version: 1.75
scsiModePageOffset: response length too short, resp_len=4 offset=4 bd_len=0
>> Terminate command early due to bad response to IEC mode page
Error Counter logging not supported
scsiModePageOffset: response length too short, resp_len=4 offset=4 bd_len=0
@penryu
penryu / gist:784026
Created January 18, 2011 05:36
parse simple INI-style config file without eval or non-standard modules
#!/usr/bin/perl -wT
# No non-standard modules.
# Not ideal for non-simple field names;
# suggest a split-based algo for those.
# *shrug* I got bored.
use strict;
my $cfg_file = "testdata.cfg";
@penryu
penryu / gist:914764
Created April 12, 2011 01:42
goofing off
/*
* strkittens
*
* Conceptually, strcat() is a sequence of strlen() followed by a
* strcpy() using the offset derived from strlen().
* These functions build on that idea.
*
* None of the FreeBSD, OpenBSD, nor Linux/glibc implementations
* of strcat() use this delegation to strcpy(), presumably because
* the pointer-based strcpy() algorithm, when used with short strings,
#!/usr/bin/env racket
#lang racket/base
(require net/base64)
;; tunables
(define amount 32)
(define sources (list "/dev/urandom" "/dev/random"))
(define (read-entropy amt srcs)
@penryu
penryu / gist:1223760
Created September 17, 2011 08:34
Playing with the Fisher-Yates shuffle and named lets. Comments/corrections welcome.
(define (vector-swap! v idx1 idx2)
(let ((temp (vector-ref v idx1)))
(cond ((= idx1 idx2) v)
(else (vector-set! v idx1 (vector-ref v idx2))
(vector-set! v idx2 temp)
v))))
(define (vector-shuffle! vec)
(let vec-shuf-helper ([v vec]
[n (vector-length vec)])
#!/bin/bash
# decomp - decompress arbitrary archives by extension
# author: Tim Hammerquist <penryu@gmail.com>
UNZIP=`which unzip`
TAR=`which tar`
extract_zip="$UNZIP"
extract_tgz="$TAR zxf"
extract_tbz="$TAR jxf"