Skip to content

Instantly share code, notes, and snippets.

View lalinsky's full-sized avatar

Lukáš Lalinský lalinsky

View GitHub Profile
my $tree = HTML::TreeBuilder::XPath->new;
$tree->parse_content($response->content);
my @elements = $tree->findnodes("//div[id='foo']");
my $content = @elements > 0 ? $elements[0]->as_HTML : '';
@lalinsky
lalinsky / fp-find.py
Created July 22, 2011 18:02
Locate audio snippets in a longer stream
def format_time(secs):
return "%d:%02d" % (secs / 60, secs % 60)
def invert(arr):
"""
Make a dictionary that with the array elements as keys and
their positions positions as values.
>>> invert([3, 1, 3, 6])
@lalinsky
lalinsky / fpcmp.py
Created August 8, 2011 16:52
Very simple way to compare Chromaprint fingerprints
import chromaprint
popcnt_table_8bit = [
0,1,1,2,1,2,2,3,1,2,2,3,2,3,3,4,1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,
1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,
1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,
2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,
1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,
2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,
@lalinsky
lalinsky / ffmpeg-configure-osx.sh
Created October 20, 2011 14:00
Configure static audio-only FFmpeg on OS X
#!/bin/sh
./configure \
--prefix=$PREFIX \
--enable-cross-compile \
--arch=$ARCH \
--target-os=darwin \
--cc="/usr/bin/gcc-4.0" \
--extra-ldflags="-isysroot /Developer/SDKs/MacOSX10.4u.sdk -mmacosx-version-min=10.4 -arch $ARCH" \
--extra-cflags="-isysroot /Developer/SDKs/MacOSX10.4u.sdk -mmacosx-version-min=10.4 -arch $ARCH" \
@lalinsky
lalinsky / fpserver.sh
Created December 15, 2011 11:09
Acoustid Index startup script (FreeBSD)
#!/bin/sh
# PROVIDE: fpserver
# KEYWORD: shutdown
#
# Add the following lines to /etc/rc.conf.local or /etc/rc.conf to
# enable fpserver:
#
# fpserver_enable (bool): Set to NO by default. Set it to YES to
# enable fpserver.
@lalinsky
lalinsky / gist:1574473
Created January 7, 2012 11:18
MusicBrainz Server Setup on Ubuntu
sudo apt-get install cpanminus liblocal-lib-perl libossp-uuid-perl
sudo apt-get install libxml2-dev libpq-dev libexpat1-dev
echo 'eval `perl -Mlocal::lib`' >>~/.bashrc
eval `perl -Mlocal::lib`
perl Makefile.PL
cpanm -n .
sudo apt-get install postgresql-server-dev-8.4 gcc-4.4 libicu-dev postgresql-contrib-8.4
cd postgresql-musicbrainz-collate/
make PG_CONFIG=/usr/lib/postgresql/8.4/bin/pg_config
select id, mbid, (length/60)::text || ':' || (length%60)::text from submission where id in (select distinct submission_id from track_mbid_source where track_mbid_id =1231384);
id | mbid | ?column?
----------+--------------------------------------+----------
24884813 | 6afd8432-f56e-44b0-8331-ce62fdf408fc | 4:1
16685155 | 06d955ce-b888-4bdc-a15f-b206a2f7ac77 | 4:3
1504569 | 5f5335d6-9151-42a9-a3ee-b3ba756228a8 | 4:3
2959818 | 6afd8432-f56e-44b0-8331-ce62fdf408fc | 4:1
11888389 | 5f5335d6-9151-42a9-a3ee-b3ba756228a8 | 4:3
8861348 | 5f5335d6-9151-42a9-a3ee-b3ba756228a8 | 4:3
echo "DROP TYPE cover_art_presence;" | ./mbslave-psql.py
echo "ALTER TABLE release_meta DROP COLUMN cover_art_presence;" | ./mbslave-psql.py
./mbslave-import.py mbdump-derived.tar.bz2
./mbslave-sync.py
./mbslave-psql.py <sql/updates/20120105-caa-flag.sql
echo "UPDATE replication_control SET current_schema_sequence = 14;" | ./mbslave-psql.py
./mbslave-sync.py
@lalinsky
lalinsky / ingest.php
Created April 18, 2012 20:34
Simple audio fingerprint matching in PHP
<?php
include "utils.php";
$fp = parse_fp($_GET['fp']);
$dbh = new PDO('mysql:host=localhost;dbname=fingerprint', 'fingerprint');
$dbh->beginTransaction();
$sth = $dbh->prepare("INSERT INTO fp (length) VALUES (?)");
@lalinsky
lalinsky / gist:2821278
Created May 28, 2012 21:25
CMakeLists.txt for libofa
PROJECT(libofa)
SET(PROJECT_VERSION 0.1.1)
# 1. If the library source code has changed at all since the last update, then increment revision.
# 2. If any interfaces have been added, removed, or changed since the last update, increment current, and set revision to 0.
# 3. If any interfaces have been added since the last public release, then increment age.
# 4. If any interfaces have been removed since the last public release, then set age to 0.
SET(libofa_SOVERSION_CURRENT 0)
SET(libofa_SOVERSION_REVISION 2)
SET(libofa_SOVERSION_AGE 0)