timdoug's tidbits


2022-03-21

unpkg 4.8

It's released! Grab that macOS 12.3 compatibility while it's hot.

[/coding] permanent link

2021-03-14

unpkg 4.7

It's released! Grab that ARM goodness while it's hot.

[/coding] permanent link

2019-10-23

unpkg 4.6

It's released! Grab that 64 bit Catalina goodness while it's hot.

[/coding] permanent link

2014-12-17

Using the TCP MD5 Signature Option in Linux

It's entirely undocumented, for good reason. In case you also have a peculiar interest in RFC2385, this is what you need to do:

#include <linux/tcp.h>

...

struct tcp_md5sig md5sig;
char *key = "foobar";

/* addr is the struck sockaddr * passed to connect(2), from getaddrinfo() or otherwise */
memcpy(&md5sig.tcpm_addr, addr, sizeof addr);

md5sig.tcpm_keylen = strlen(key);
memcpy(&md5sig.tcpm_key, key, md5sig.tcpm_keylen);

setsockopt(sockfd, IPPROTO_TCP, TCP_MD5SIG, &md5sig, sizeof md5sig);
Not actually that hard. A successful application, with -M and the key passed to tcpdump, will show md5valid in the TCP options. An incorrect key will show md5invalid.

[/coding] permanent link

2010-08-27

unpkg 4.5

It's released! Grab it while it's hot.

[/coding] permanent link

2010-07-26

Converting a .mkv file to .mp4 to play on the iPad

Problem: you acquire a MKV file you want to play on your iPad. It's already H264/AAC, which the iPad can handle, so you don't want to re-encode it.

Solution: extract the tracks with mkvextract, and mux them into an iPad-friendly MP4 with MP4Box.

  1. Get a GPAC Subversion snapshot from http://gpac.sourceforge.net/.
  2. Build it. It's a bit finicky, and it will probably crap out looking for nonexistent wxwidgets libraries, but hopefully before that it'll create an MP4Box binary in bin/gcc.
  3. Grab a Mac OS X binary of MKVToolnix. Its dependencies are pretty extensive, so I used the binary available here.
  4. Determine what's in the mkv container: Mkvtoolnix.app/Contents/MacOS/mkvinfo Foo.mkv
  5. It'll tell you that, e.g., track one is H264 video at 24 fps, and track two is AAC.
  6. Extract the tracks accordingly: Mkvtoolnix.app/Contents/MacOS/mkvextract tracks Foo.mkv 1:Foo.h264 2:Foo.aac
  7. Put them back together in an MP4: MP4Box -add Foo.aac -add Foo.h264 -fps 24 Foo.mp4

Sometimes, though, you'll get audio in a non-AAC format (e.g., MP3 or AC3). This requires conversion.

  1. Download, make, and install the libfaac library. (We'd use FFmpeg's internal AAC encoder, but currently it's broken.)
  2. Do the same with FFmpeg, making sure to point it to libfaac appropriately.
  3. Convert the extracted audio file to AAC: ffmpeg -i Foo.ac3 -acodec libfaac -ab 192k Foo.aac
  4. Then use MP4Box as before, but with your new .aac file.
Thanks to this thread and this blog post.

[/coding] permanent link

2010-07-23

DuckDuckGo search box in JavaScript

Sometimes, at work, we have terrible internet latency. This makes every page loaded count. I use DuckDuckGo as my primary search engine, and sometimes poor caching and latency combine to create a few seconds between starting to load the page and entering my query. So I whipped up a little Bookmarklet to bring up an equivalent search box, instantly. Hooray JavaScript! (The only time I'll ever say that...)

Here, drag: DDG

Works wonderfully as a hot-key, e.g., cmd-2 in Safari as the second link in my Bookmarks bar.

[/coding] permanent link

2010-04-15

METAL Basic for the Mac (or: yet another young kid's introduction to programming)

Like many programmers, I was introduced to the craft through a BASIC dialect, specifically a MacOS-only one named METAL. I was taking extracurricular classes in C++ at the time, but the SIOUX (Simple Input Output User eXchange, i.e., the I/O offered by cin/cout) Mac runtime we used couldn't do anything graphical.

I can't remember how I stumbled upon METAL, but I have fond memories of heading to my friend's house, putting Cowgirl by Underworld on repeat, and seeing what we could get this simple language to do. We never created anything ground-breaking, of course -- a few simple point-'n'-shoot pseudo-3D games, for example -- but man would those coding sessions be serious.

Upon entering high school, we moved on to bigger and better languages. My friend found the Macromedia Flash MX (ca. 2002?) application on our school's computers, and I somehow dove deep into Java. I remember when version 1.5 (...5.0) came out, and thinking that generics and auto(un)boxing were the shit.

Anyway. METAL v1.7.3 was nevertheless my bread and butter for a few years. I recall checking its website once, noticing that an incredible v2.0 was on its way. To this day, the website still has "METAL v2.0 ULTRA" listed as ??? percent done.

That is, the Wayback Machine's version of the website. Naturally, the author graduated, and his personal website disappeared. It's still available here: http://web.archive.org/web/20080327004511/www.iit.edu/~sarimar/GDS/. METAL can be downloaded from there.

It still runs on Snow Leopard through Rosetta. Trying to run code results in a crashing runtime, but when "compiled" the resultant executable works fine.

If I ever stumble upon some old code I've written in METAL I'll post the atrocities. And I owe its author, Marin Saric, a beer or two.

[/coding] permanent link

2009-08-21

When bit twiddling, make sure to use unsigned types.

This public service announcement was brought to you by the "Why The Fuck Don't My Bit Shifts Work" Department.

Goodness, that was amateur.

[/coding] permanent link


© 2006-24 timdoug | email: "me" at this domain
So necessary