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 / 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'
@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 / 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 / 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 / .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 / 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 / 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.

@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 / 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 / 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('')