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 / 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__) }
@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 / 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 / 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 / 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 / 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 / clearabledatepicker.js
Created August 22, 2013 16:24
Trying to get a jQuery-UI datepicker with a "clear" button on it is surprisingly difficult.
$(function() {
var datePickerCloseEventBound = false, currentDateInput
enableClearDatePickerButton = function(dateInput) {
currentDateInput = dateInput
if (datePickerCloseEventBound) return;
// sadly. the .ui-datepicker-close button doesn't exist yet :(
$('.ui-datepicker-close').click(function() {
$(currentDateInput).val('')
@sycobuny
sycobuny / split.vim
Last active December 22, 2015 09:18
My really cheap-n-easy way to setup my editing environment for multi-part multi-section pieces
:e parts/harp_3/left/01_credits.ly
:vert sp parts/harp_2/left/01_credits.ly
:vert sp parts/harp_1/left/01_credits.ly
:sp parts/harp_1/right/01_credits.ly
:winc l
:sp parts/harp_2/right/01_credits.ly
:winc l
:sp parts/harp_3/right/01_credits.ly
:tabnew parts/harp_3/left/02_narration.ly
@sycobuny
sycobuny / sanitize.php
Created September 13, 2013 17:12
A quick hack to make it easier to sanitize outputs en masse before displaying them to the user.
<?php
function sanitize_for_html(&$entity, $flags = ENT_QUOTES) {
if (is_array($entity)) {
$iterator = $entity;
}
elseif (is_object($entity)) {
$iterator = get_object_vars($entity);
}
else {
@sycobuny
sycobuny / vim-question.md
Last active December 23, 2015 18:19
tl;dr: How do you insert line breaks at the beginning and end of a visual block in vim?

Since I've just started using snipMate, I was playing around and used table to get a pre-built table. Pretty nicely, it dropped a whole lot of text in place for me:

<table border="0">
    <tr><th>Header</th></tr>
    <tr><th>Data</th></tr>
</table>

But, bypassing the fact that I don't like this default table setup (it uses for the same data cell, for some reason, and does *not* use or ``, which may be uncommon but I tend to use them), we'll skip to another problem that presented itself.