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 / tmux-attach.bash
Created December 27, 2012 18:26
Script for re-attaching to existing tmux sessions while maintaining window independence, à la `screen -x`
#!/bin/bash
#
# Re-modified script from
# https://mutelight.org/practical-tmux
# Which is modified from:
# http://forums.gentoo.org/viewtopic-t-836006-start-0.html
#
# chmod +x it and put it in your $PATH for easy use; I stuck it in
# ~/.tmux-attach.bash and added an alias for it, do whatever you like.
@sycobuny
sycobuny / dynamic_routes.rb
Created December 13, 2012 17:12
Displaying loading a dynamic route via ENV, but with a default
require 'sinatra'
asdf = ENV['asdf'] || '/asdf'
get asdf do
'asdf'
end
@sycobuny
sycobuny / Gemfile
Created November 29, 2012 19:12
A bare-bones "just getting started" sinatra+sequel script
source :rubygems
gem 'sinatra'
gem 'sequel'
gem 'pg'
@sycobuny
sycobuny / js_question.md
Created November 20, 2012 20:17
Question about prototype declarations in JS and "standard practice"

There's a couple ways to define an "object" in JavaScript.

The following uses a standard function to declare a class and some attributes and an accessor:

function Car(make, model, year) {
    this.make  = make;
    this.model = model;
    this.year  = year;
@sycobuny
sycobuny / topics.md
Created November 19, 2012 16:13
Possible Topics for 2012-10-19 Programmer's Meeting

Intro to Sass

http://github.com/sycobuny/sass_presentation

This is an intro to the "Sass" (not "SAS") language, which is a templating language used to generate CSS from a more minimal set of instructions, as well as a set of functions which can help with design and layout (mathematical operators in CSS!)


Code Smells (and what to do about them)

@sycobuny
sycobuny / 001_start.pl
Created November 16, 2012 20:31
Example Migration in Perl
PLModel::Migration {
$migration->table users => sub {
$table->primary_key;
$table->text name => {null => FALSE};
$table->text login => {null => FALSE, unique => TRUE};
$table->text salt => {null => FALSE};
$table->text password => {null => FALSE};
};
@sycobuny
sycobuny / migrate.php
Last active October 12, 2015 20:08
Basic PHP database migration script
<?php
/**
* Set up the database connections and other libraries
*/
require(
join(DIRECTORY_SEPARATOR,
array(dirname(__FILE__), '..', '..', 'pg_connect.php'))
);
@sycobuny
sycobuny / prt.pl
Last active October 11, 2015 08:37
My Swiss-Army Script, Redux
#!/usr/bin/env perl
use warnings;
use strict;
my ($home, $psql, $pg_ctl, $pg_dump, $code_root, $mig_dir, $replication,
$localdb, $rvm, $rubyver, $gemset_name, $gemset, $ruby_bin, $padrino,
$rep_port, $local_port);
my ($SUPER, $OWNER, $PRODDB, $DEVDB, $TESTDB, $TESTTMPLDB);
@sycobuny
sycobuny / myavg.sql
Created September 14, 2012 14:55
Cheap non-aggregate MAX() and AVG() functions
CREATE OR REPLACE
FUNCTION MYAVG(VARIADIC NUMERIC[])
RETURNS NUMERIC
LANGUAGE SQL
AS 'SELECT AVG(unnest) FROM UNNEST($1)';
@sycobuny
sycobuny / unique_with_null.sql
Created September 10, 2012 15:59
Possible Solution to Unique-With-NULL Problem
-- you may have to declare the function after the table exists.
CREATE FUNCTION check_unique_ex(TEXT, TEXT, TEXT)
RETURNS BOOLEAN
LANGUAGE SQL
AS $BODY$
SELECT EXISTS (
SELECT 1
FROM ex
WHERE a IS NOT DISTINCT FROM $1 AND
b IS NOT DISTINCT FROM $2 AND