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 / newenv_problem.tex
Last active December 25, 2015 05:59
Trying to figure out how to apply a nesting of \newenvironment in a manner reminiscent of OO inheritance (at least, that's the way it stacks in my brain)
\newenvironment{someSection}{%
% some \newcommands go here
\header{Some Section}%
\addvspace{\vpad}%
\begin{adjustwidth}{\extraMargin}{\extraMargin}%
}{%
\end{adjustwidth}%
\addvspace{\vpad}%
}
@sycobuny
sycobuny / .gitconfig
Last active December 30, 2015 21:09
Do annotated tags automatically based on branches, for doing a rolling upgrade from puppet 2.x to puppet 3.x.
[alias]
root = rev-parse --show-toplevel
current-branch = rev-parse --abbrev-ref HEAD
ls-untracked = ls-files -o --exclude-standard
release = !"$(git root)/.git/local-commands/release.pl"
@sycobuny
sycobuny / error_dump.php
Created January 17, 2014 16:28
Dump PHP variables into the error log instead of the page when debugging
<?php
/**
* Dump a variable to error_log instead of the main page
*
* To do debugging, it's often preferable to stick output into the
* error log rather than the main page, in case you might forget to remove
* a statement (it does happen) - but you can't do `var_dump()` or
* `print_r()` to output, or at least you couldn't before. This will get
* the output of those functions and send them to error_log(), reformatted
@sycobuny
sycobuny / latest-ruby.zsh
Created January 28, 2014 15:09
Get the latest ruby version installed via RVM
RUBY_VER=$(rvm list strings | cut -d\- -f2 | sort -rn | head -n1) echo "ruby-$RUBY_VER-p$((for v in $(rvm list strings | grep "ruby-$RUBY_VER" | cut -d\- -f3); do; echo ${v[2,${#v}]}; done) | sort -rn | head -n1)"
@sycobuny
sycobuny / my_app.rb
Last active August 29, 2015 13:55
Just a simple file to build standard routes for a set of objects that will all behave in a similar way
class MyApp < Sinatra::Base
RestfulObjects = [
SampleObject
]
require 'restful_sinatra.rb'
end
@sycobuny
sycobuny / profile.rb
Created February 3, 2014 21:17
Checking whether Class.new makes permanent refs (with cribbing from https://gist.github.com/rjackson/5071864 h/t @nevern02)
def m(m)
puts m
puts " Currently at: #{`ps -o rss= -p #$$`.to_i / 1024} MB"
puts " #{GC.stat.inspect}"
end
m 'Started';
10_000_000.times { Class.new }
m 'Made 10,000,000 (unstored) objects'
10
Argument "hello" isn't numeric in addition (+) at test.pl line 9.
1
@sycobuny
sycobuny / migrate.php
Created April 22, 2014 13:06
An iteration of my migrator script for PHP
<?php
/**
* Set up the database connection. Note that these require either a
* connection string be provided by the $PHP_DATABASE_STR env variable, a
* filename be provided by the $PHP_CONNECTION_SCRIPT variable, or a
* filename matching the parameters demanded by
* Migrator::default_connection_script(), the latter two of which must
* exist, or the script will fail at this point.
*/
<?php
$output = '';
foreach (scandir(session_save_path()) as $x => $dir) {
if (!preg_match('/^sess_(.*)/', $dir, $matches)) continue;
ob_start();
session_id($matches[1]);
session_start();
# we assume $dbh gets assigned somewhere else
sub do_query {
my ($name, $wildcard) = @_;
my ($sth) = $dbh->prepare(<<<QUERY);
SELECT *
FROM some_table
WHERE name = ? AND
address LIKE CONCAT('%', ?, '%');
QUERY