Skip to content

Instantly share code, notes, and snippets.

View jeffa's full-sized avatar

Jeff Anderson jeffa

View GitHub Profile
@jeffa
jeffa / d3table.html
Created March 24, 2013 02:37
Dynamically generated HTML table via D3.
<!DOCTYPE html>
<html lang='en'>
<head>
<link href='/css/bootstrap.css' rel='stylesheet'>
<script src='/js/d3.v2.min.js'></script>
<script src='/js/jquery.min.js'></script>
<script src='/js/jquery.ba-bbq.min.js'></script>
</head>
<body>
@jeffa
jeffa / image-service.rb
Last active December 17, 2015 16:29
Create an image manipulation web service. The service should be able to proxy images from a source, manipulate them, and return a new image.
require 'sinatra'
require 'open-uri'
require 'RMagick'
include Magick
get '/' do
'This service is currently REST only.
You will have to manually request service by typing and entering your own URI like so:
<p><tt>acme.com/&lt;image_url&gt;?w=XX&h=XX</tt></p>'
end
@jeffa
jeffa / make-dist-tests.pl
Last active December 20, 2015 22:18
Given a list of existing distribution folders, build the boiler plate tests and move them to some final destination. Probably too silly for anyone else's needs ...
#!/usr/bin/perl -l
use strict;
use warnings;
use File::Temp qw( tempdir );
# init
chomp( my @dists = <DATA> );
my $root = '/Users/jeffa/perl/tmp/';
my $wipe = $root . '*';
@jeffa
jeffa / queens.c
Last active December 21, 2015 22:58
A threaded solution for N-Queens.gcc queens.c -o queens -lpthread
#include <stdio.h>
#include <pthread.h>
#include <getopt.h>
#define MAX_DIMENSIONS 25
#define MAX_THREADS 9
typedef struct {
int size;
int top;
@jeffa
jeffa / nyquist.pl
Last active December 21, 2015 22:58
Demonstration of Nyquist's Theorem.
use strict;
use warnings;
use Audio::Wav;
use Math::Complex;
use constant TWO_PI => pi() * 2;
my $wav = Audio::Wav->new();
my $sample_rate = 44100;
my $bits_sample = 16;
@jeffa
jeffa / xml2midi.pl
Created August 29, 2013 14:18
Demonstration of the defunct 4ML language. This script converts the 4ML XML markup into actual MIDI events.
use strict;
use warnings;
use MIDI;
use XML::Simple;
my $xml = XMLin(\*DATA);
my $song = $xml->{SONG};
my @note = @{ $song->{NOTE} };
my $title = $song->{title} || 'unknown';
my $author = $song->{author} || 'unknown';
@jeffa
jeffa / Rot26.pm
Created August 29, 2013 14:19
Twice the power of Rot 13.
=head1 NAME
Crypt::Rot26 - Encrypt data with TWICE the power of Rot13!!
=head1 SYNOPSIS
use strict;
use Crypt::Rot26;
@jeffa
jeffa / spreadsheet.pl
Created August 29, 2013 14:21
CGI script that turns any database table into a spreadsheet in a web browser.
use strict;
use warnings;
use CGI qw(:standard);
use CGI::Carp qw(fatalsToBrowser);
use DBI;
use DBIx::XHTML_Table;
print header(), start_form();
@jeffa
jeffa / rotate-spreadsheet.pl
Created August 29, 2013 14:23
Transpose Excel docs from "portrait" to "landscape."
use strict;
use warnings;
use Math::Matrix qw(transpose);
use Spreadsheet::ParseExcel::Simple;
use Spreadsheet::WriteExcel::Simple;
my $xls = Spreadsheet::ParseExcel::Simple->read('old.xls');
my @data;
for ($xls->sheets) {
while ($_->has_data) {
use strict;
use warnings;
use DBI;
# connect
my $dbh = DBI->connect(
qw(DBI:mysql:mp3:host user pass),
{ RaiseError => 1 }
);