Skip to content

Instantly share code, notes, and snippets.

View sycobuny's full-sized avatar

Stephen Belcher sycobuny

  • Kelly Services, NIH/NIA
  • Baltimore, MD
View GitHub Profile
@sycobuny
sycobuny / get_time_slots.sql
Created August 11, 2013 00:17
Fetch potential valid time slots for a "workshops" table where multiple workshops may occur simultaneously, with non-concurrent start/end times.
WITH
times AS (
SELECT ROW_NUMBER() OVER (ORDER BY time) AS sort, time
FROM (
SELECT DISTINCT time
FROM (
SELECT start_time AS time
FROM workshops
WHERE TO_CHAR(day, 'FMDay') = 'Friday'
UNION
@sycobuny
sycobuny / migrate.sh
Created July 9, 2013 13:56
A simple migration script runner that assumes SQL-based migrations, with related downward migrations in a down/ subdirectory, and PostgreSQL as the backing database, with simple access requirements.
#!/bin/bash
# default to apache/postgres if env is not set up; probably means we're on
# a vagrant VM; same for work dir
user=${PGUSER:-apache}
db=${PGDATABASE:-postgres}
base=${BASEDIR:-/vagrant}
# get the current schema version, or assume we're on an empty DB/version 0
cur_version=$(psql -t -d $db -U $user -c "SELECT schema_version()" \
@sycobuny
sycobuny / pre-commit.pl
Created June 10, 2013 19:02
A (relatively) easy-to-extend pre-commit hook for linting multiple languages in git.
#!/usr/bin/env perl
use warnings;
use strict;
my ($fail) = 0;
my ($linters) = {
php => [qr/\.(php|inc)$/i, 'php -l', '%s --'],
perl => [qr/\.(pl|pm|t)$/i, 'perl -cw', '%s'],
};
@sycobuny
sycobuny / merge
Last active December 17, 2015 17:09 — forked from rintaun/merge
sycobuny@valhalla:~/gittest$ git init .
Initialized empty Git repository in /home/sycobuny/gittest/.git/
sycobuny@valhalla:~/gittest$ touch first
sycobuny@valhalla:~/gittest$ git add first
sycobuny@valhalla:~/gittest$ git commit -m "first"
[master (root-commit) be18d08] first
0 files changed
create mode 100644 first
sycobuny@valhalla:~/gittest$ git checkout -b branch
Switched to a new branch 'branch'
@sycobuny
sycobuny / totally_reasonable.txt
Created May 15, 2013 23:44
The total package dependencies for redhat-lsb. This seems reasonable, as -- as far as I'm aware -- the job I need it for is basically parsing /etc/redhat-release.
==============================================================================================================================================================================================================================================================================================================================
Package Arch Version Repository Size
==============================================================================================================================================================================================================================================================================================================================
Installing:
redhat-lsb
@sycobuny
sycobuny / lexical_subs_sad.pl
Last active December 17, 2015 07:08
Kinda sad that this doesn't actually work :-(
#!/usr/bin/env perl
use v5.18;
use warnings;
no warnings qw(experimental::lexical_subs);
use feature qw(lexical_subs);
package MyObject {
sub new { bless({}, __PACKAGE__) }
#!/usr/bin/env perl
use warnings;
use strict;
# some example values to test
our (%STUFF) = ( # just doin' a hash, like a boss.
SOME_KEY => 'some_value',
SOME_OTHER_KEY => 'some_other_value',
);
@sycobuny
sycobuny / wacky_switch.js
Created April 26, 2013 18:11
This is a wacky way to implement a "switch"-type construct I just thought would be interesting to use
var addCell = function($row, inner, addAs) {
var $cell = $(document.createElement('td'))
{
html: function() { $cell.html (inner) },
text: function() { $cell.text (inner) },
child: function() { $cell.append(inner) }
}[addAs ? addAs : 'text']()
$row.append($cell)
@sycobuny
sycobuny / lists.pl
Last active December 16, 2015 13:49
A perl rewrite of the second base list implementation from http://stevelosh.com/blog/2013/03/list-out-of-lambda/
#!/usr/bin/env perl
use v5.14;
my $empty_list = sub {
shift->(undef, undef, 1);
};
my $prepend = sub {
my $el = shift;
@sycobuny
sycobuny / gist:5436818
Created April 22, 2013 17:13
Git had a weird little hiccup, and I'm wondering what could have caused it
$ git status
# On branch master
# Your branch is behind 'origin/master' by 19 commits, and can be fast-forwarded.
#
nothing to commit (working directory clean)
$ git pull origin master
[output snipped]
$ git status
# On branch master
# Your branch is ahead of 'origin/master' by 1 commit.