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 / git.pp
Created February 16, 2012 03:15
A simple example of a puppet config with git automatic deployment based on "release-#" tags
class git {
package { 'git':
ensure => installed,
}
define repository($project = $name, $cwd, $dir = "$cwd/${project}",
$repo = "githost:${project}.git", $no_ensure = 0) {
$require = $no_ensure ? {
1 => [Package['git']],
default => [Package['git'], File[$cwd]],
@sycobuny
sycobuny / overlaps.rb
Created March 15, 2012 02:49
Add Range#overlaps to deal with constructing an OVERLAPS clause for queries in Sequel
class Range
def overlaps(range)
Sequel::SQL::PlaceholderLiteralString.new(
"(?, ?) OVERLAPS (?, ?)",
[
self.first, self.end,
range.first, range.end
],
true
)
<?php
class Model {
/* public Model->load(Integer)
* returns $this
*
* Pulls data from the database for a given model into the object. Note
* that this clears any state (modifications/etc.) that have been set
* on the object first, for any Model-controlled columns.
@sycobuny
sycobuny / example.sql
Created April 23, 2012 01:28
Multiple-choice DB Schema
CREATE TABLE users (
phone_number TEXT
UNIQUE
NOT NULL,
first_name TEXT,
last_name TEXT,
username TEXT
NOT NULL,
PRIMARY KEY (phone_number)
@sycobuny
sycobuny / Accessor.pm
Created April 23, 2012 17:19
Thoughts on a PLModel (like PGModel but for Perl)
package PLModel::Accessor;
use warnings;
use strict;
sub TIESCALAR {
my ($class) = shift;
my ($curval, $colname, $object) = @_;
return bless({
@sycobuny
sycobuny / app.psgi
Created April 23, 2012 19:55
Example plack script
my $app = sub {
my ($status) = 200;
my ($headers) = [ 'Content-type' => 'text/plain' ];
my ($body) = [ "SUP YOU GUYS\n", "IT'S MEEEEEEE\n" ];
return [$status, $headers, $body];
};
use Plack::Builder;
builder { $app }
@sycobuny
sycobuny / perldoc-md.pl
Created April 25, 2012 17:06
perldoc-md main file
#!/usr/bin/env perl
use v5.14;
use warnings;
use File::Spec;
use IO::File;
use autodie;
my ($dir);
use v5.14;
use warnings;
package PackageA {
# put subs in here and then coderefs passed to PackageA->configure() can use these methods
# as though they're in the right package
package PackageA::ConfigurationSubs {
sub hello {
say "hello, world";
}
@sycobuny
sycobuny / gist:2563131
Created April 30, 2012 22:16
optree output of crazier.pl (see https://gist.github.com/2499830)
>>> perl -MO=Concise,-exec crazier.pl
1 <0> enter
2 <;> nextstate(main 66 crazier.pl:4) v:%,*,&,{,$,2048
3 <{> enterloop(next->8 last->8 redo->4) v
4 <;> nextstate(PackageA 51 crazier.pl:7) v:%,*,&,{,$,2048
5 <{> enterloop(next->7 last->7 redo->6) v
6 <0> stub v
7 <2> leaveloop vK/2
8 <2> leaveloop vK/2
9 <;> nextstate(main 69 crazier.pl:41) v:%,*,&,{,$,2048
@sycobuny
sycobuny / parsenums.rb
Created May 3, 2012 02:23
Simple parsing script for Justin
def event(queuename, *nums)
puts "Got event for #{queuename}!"
puts " nums: #{nums.join(', ')}"
end
begin
while line = $stdin.readline
args = line.chomp.split(/\s+/)
1.upto(args.length - 1) { |x| args[x] = args[x].to_i }