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 / 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 / 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 / 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)
<?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 / 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
)
@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 / test_script.pl
Created February 2, 2012 17:40
Demonstrating the "Scribe" Logger
#!/usr/bin/perl
use warnings;
use strict;
use Scribe;
my ($logger) = Scribe->new(
minlog => Scribe::DEBUG6,
@sycobuny
sycobuny / abstract.py
Created January 30, 2012 01:39
Get the selection of a wx.ComboBox in python
# line 37 in llm/view/dialog/library/abstract.py
self.type = wx.ComboBox(panel,
-1,
choices=["CD/DVD/Blu-Ray", "Book/Magazine"],
style=wx.CB_READONLY)
sbs.Add(self.build_line(wx.StaticText(panel, -1, "Type:"), self.type))
# new line 51 in llm/view/dialog/library/abstract.py
@sycobuny
sycobuny / block_with_eval.rb
Created September 24, 2011 20:44
We're asserting the hell out of some arguments
module Sequel
class Model
STRIP_UNSAFE_VAR_NAMES = /[^a-z_]/i
#########
protected
#########
#
# Asserts that arguments match a certain class, and raises errors if
@sycobuny
sycobuny / chanserv_database.rb
Created September 3, 2011 05:31
Thoughts on Kythera ChanServ DB
module Database
class Account
one_to_many :chanserv_channel_founders,
:class_name => Database::ChanServ::Channel,
:foreign_key => :founder_id
one_to_many :chanserv_channel_successors,
:class_name => Database::ChanServ::Channel,
:foreign_key => :successor_id
one_to_many :chanserv_privileges,
:class_name => Database::ChanServ::Privilege