Monday, January 25, 2010

moving!

The posts that are on this blog are moving to my main site!
http://www.rexroof.com/

see you there!
-Rex

Tuesday, March 24, 2009

movie time

creating an mpeg from a series of jpg images:

ffmpeg -f image2 -i '%03d.jpg' -sameq -f mpeg2video file.mpg

Tuesday, May 02, 2006

missing eject button

I was missing my eject button in the menu bar for my mac. This was causing me problems because I don't have a mac keyboard on it and so, if theres no cd in the drive, I had limited options for getting the drive open. Then I found out how to return the eject icon to my finder toolbar:


open /System/Library/CoreServices/Menu\ Extras/Eject.menu


or, if you want to use the finder, open a finder window, click cmd-shift-g and type

/System/Library/CoreServices/Menu Extras/

hit enter, and then double-click the Eject icon.

sweet!

Tuesday, April 25, 2006

flickr and unix is awesome

I've been toying around with flickr and downloading random images based on tags. I just wrote a one-liner that grabs a random popular flickr tag, it looks like this:


GET http://flickr.com/photos/tags/ | grep '/photos/tags/[a-z]' | cut -f4 -d/ | random -f - | head -1


note: the random command is something I've only found in FreeBSD. it could easily be replaced with a perl one-liner to shuffle.

this prints out a single, random, popular tag from flickr. used in combination with my perl script that picks a random picture based on tag, I can get some randomly awesome pictures:


slather -t `randomtag`


perhaps soon I'll post slather.

Monday, September 19, 2005

Unix Domain Sockets in Perl

I know this has been done dozens of times before, but it's been a real headache for me lately. A full example of how to use IO::Socket::UNIX is not really available anywhere on the web. All of the socket info for perl seems to assume you've been doing socket programming in C for years, and theres very limited info on doing Unix Domain Sockets. it all seems to be about inet sockets. which, of course, relates a lot to Unix Sockets, but there are some differences.

okay, here is my working example. Its meant to be run twice, the first time it's the server, the second time it's the client.



#!/usr/bin/perl
use strict; $|++;
use IO::Socket;

my $socketfile = $ENV{HOME} . "/.sockettest";

if ( -S $socketfile ) {
# client!
my $client = IO::Socket::UNIX->new(Peer => $socketfile,
Type => SOCK_STREAM ) or die $!;
my $string = "this is some sent garbage.\n";
print $client $string;
$client->flush;
$client->close;
exit;

} else {
# server!
unlink $socketfile;
my $data;
my $server = IO::Socket::UNIX->new(Local => $socketfile,
Type => SOCK_STREAM,
Listen => 32 ) or die $!;
$server->autoflush(1);
while ( my $connection = $server->accept() ) {
my $data= <$connection>;
print $data, $/;

sleep 5;
}
}

Wednesday, March 16, 2005

iTunes share on FreeBSD

With over 33,000 songs in my library, my iTunes share here at work is very popular. iTunes has a built in connection limit that people often complain to me about hitting. So this is why I started looking into running a duplicate share on my FreeBSD server.

first thing I did was set up nfs on my Mac OS X box to share to my mac, handily if you just write an /etc/exports file and reboot, the NFS server just starts. here's my /etc/exports file:

/Volumes/Music -mapall=rex shaolin

/Volumes/Music is where my music is, rex is my user's shortname, and shaolin is the machine hostname for my FreeBSD server that will want to mount the share.

then, on my FreeBSD box I put this in my /etc/fstab:


mogu:/Volumes/Music /music nfs ro,intr,noauto 0 0

intr is nice so that when nfs goes down my df commands don't hang. I'll probably take out the noauto once I figure out if this setup is working right.
after that I just did: mkdir /music ; mount /music , as root, of course.

all of this I did after I found this handy site:

Setting up an iTunes server in FreeBSD

This page was very helpful, but I found some of the info out of date and some dependancies broken. so here's my rundown (read that page before continuing)

First, install daapd. it's in /usr/ports/audio/daapd.

In the above instructions the info on daapd is correct, but I had many issues getting the port to build. The dependancies didn't seem to work out of the box, the error it gave me lead me to build multimedia/mpeg4ip manually. do this:

# cd /usr/ports/multimedia/mpeg4ip-libmp4v2
# make install clean
# cd /usr/ports/multimedia/mpeg4ip
# make install

then, it gets tedious. to get the mpeg4ip port to build, I had to edit some makefiles. I kept running that last command over and over, editing files as I went. The first errors were about mp4.h not found. this happened about 3 times; when it did, I noted from the error what directory it was in, then edited the Makefile in that directory and added
-I$(src_topdir)/lib/mp4v2
to the INCLUDES= line. for some reason this was omitted someplace. I'll e-mail the maintainer, hopefully it'll be fixed when you go to build the port.

After that I got some errors that were warnings treated as errors because -Wall was in the Makefile. The errors looked rather harmless, so I went into the directories in question and edited the Makefile to remove every instance of
-Wall

I think this only happened once.

The next batch of errors I had was some errors that said something along the lines of "undefined reference to `MP4IsIsmaCrypMediaTrack'", those were solved by manually rebuilding mpeg4ip-libmp4v2, which you already did, because I mentioned it above.

After mpeg4ip was installed, I went and built daapd, which rebuilt a bunch of stuff on my machine in my xlibraries. most of these things were upgrades, so I had to rebuild them by hand using cd /usr/port/dir ; make deinstall ; make reinstall. I had to do this for at least 3 ports; including pango, gtk and glib. I also got an error from /usr/ports/x11-fonts/XFree86-4-fontScalable that required me to build the port manually, that is, after manually installing a new version of make and imake. I did both of these with
portupgrade imake make
. Hopefully anyone reading this won't have ports as old as mine and won't have issues with these.

once daapd is installed you'll want to put daapd_enable="YES" in your /etc/rc.conf. and don't forget to edit your /usr/local/etc/daapd.conf, a sample is provided, and an example is shown on the page I linked above.

setting up mdnsresponder/rendezvous

the information on this in that above page is outdated. I found that I already had a mDNSResponder port, so I installed that. in fact, it's part of the dependancies of howl, which is part of the daapd dependancies. but I installed /usr/ports/net/mDNSResponder, and /usr/ports/net/howl by hand; I believe they went fairly painless. Finally I created /usr/local/etc/howl and created an mDNSResponder.conf there with these contents:

FREEBSD SERVERNAME
_daap._tcp.

3689

(note that blank line in there).

also, don't forget to add mdnsresponder_enable="YES" to your /etc/rc.conf

after that I ran

# /usr/local/etc/rc.d/mdnsresponder.sh start
# /usr/local/etc/rc.d/daapd.sh start

if you haven't changed your rc.conf these commands won't start the servers, so make sure you do that first.

this took over 10 minutes to start up the first time, I'm guessing because it had to parse my almost 160GB of music. but after that it started up rather quickly. you can watch /var/log/daapd.log to see what the server is doing.

one note, the first time I ran this, it crashed after I played with it a bit. hopefully this doesn't continue to happen.

Thursday, February 10, 2005

pladd

I've written this script a half-dozen times at least, but this is the first one that doesn't use Mac::iTunes to create the playlist. I needed something that would add a directory of mp3s to a playlist in itunes with the same name as the directory, so I wrote this:


#!/usr/bin/perl
use strict; $|++;
use warnings;
use Mac::Glue qw(:all);
my $itunes = Mac::Glue->new("iTunes");

my $dir = shift;
die "specify directory on command line\n" unless ( $dir and -d $dir );
my $playlist = $dir;
$playlist =~ s/\///g;
$playlist =~ s/\s+/_/g;

die "no playlist found\n" unless ($playlist =~ m/[a-zA-Z]/);

# check the playlist total time to see if the playlist exists already.
# $pl_time will be null if playlist doesn't exist, "0:00" for empty playlist
my $pl_time = $itunes->obj(playlist=>$playlist)->prop('time')->get;
if ($pl_time) {
print "playlist exists!\n";
} else {
$itunes->make(new => 'playlist', with_properties => { name => $playlist });
}

opendir DIR, $dir or die $!;
# only adding songs m4a, m4b, and mp3s.
my @file_list = grep { /(mp3|m4[ab])$/i } readdir (DIR);

foreach my $file (@file_list) {
print $file, $/;
# add files to playlist.
$itunes->add("$dir/$file", to => $itunes->obj(playlist=>$playlist));
# remove original
unlink "$dir/$file" or warn $!;
}



you can also find it on the code section of my webpage here.