Skip to content

Instantly share code, notes, and snippets.

View mjdominus's full-sized avatar

Mark Jason Dominus (陶敏修) mjdominus

View GitHub Profile
Mar 15 12:23:13 <\yrlnry> schacon: My coworker and I were talking about ticgit today. I was (mistakenly) looking at your github version and I was pleased at how small it was. Then he said he thought it was dead, and then we discovered that other people have continued to develop it.
Mar 15 12:23:32 <\yrlnry> schacon: How would you characterize the current status of ticgit? Do you still like it?
Mar 15 12:25:08 <schacon> i started pulling in some of the newer branches, but the tests they include are somewhat brittle
Mar 15 12:25:14 <schacon> i've been working on fixing them up
Mar 15 12:26:07 <\yrlnry> Do you consider it alive? Are you still using it yourself?
Mar 15 12:26:15 <schacon> jeffWelling fork is probably the best
Mar 15 12:26:45 <schacon> i don't currently use it much, but a lot of people do and i've been starting to work on it again
Mar 15 12:27:06 <\yrlnry> If you were starting today, would you prefer the jeffWelling fork of ticgit, or would y
  • Overview

I have a bunch of classes that represent email filters, and are backed by a legacy database. The interface to the legacy database is through DBIx::Class. A filter is essentially two things: a condition and an action. An email message is passed to the condition object, which reports whether the condition is satisfied; if so, the message is passed to the action object, which performs some action, possibly modifying the message. The legacy database principally involves two tables: mh_conds, representing conditions, and mh_actions, representing actions.

I have code that examines the tables using DBIx::Class and constructs Filter objects, and also code for the reverse direction: you can manufacture a Filter object, including its subsidiary Condition and Action objects, and then store it into the database.

The storage code is peculiar. The way it works is that Condition and Action objects each have an as_rows method, which returns a list of DBIx::Class::Row objects. To i

Little-used features list:
-P option
-u option
dump
...
.. in scalar context
formats:
in general
$: to control line breaking in a ^.... field
@mjdominus
mjdominus / gist:659737
Created November 2, 2010 15:02
Big tree query that the RDB handled just fine
String query = "select distinct a.tree.rootNode "
+
// Find the trees with three nodes a, b, and c, such that...
"from PhyloTreeNode as a, PhyloTreeNode as b, PhyloTreeNode as c, "
+
// There's a node "ab" (which will be an ancestor of both a and b)
"PhyloTreeNode as ab "
+
// All four nodes are in the same tree
"where a.tree = b.tree " + "and a.tree = c.tree " + "and a.tree = ab.tree "
@mjdominus
mjdominus / fib5.pl
Created March 28, 2011 17:42
fibonacci identity
sub choose {
my ($n, $k) = @_;
return 1 if $k == 0;
return 0 if $n == 0;
return choose($n-1, $k-1) * $n / $k;
}
sub pow5 {
my ($k) = @_;
my $p = 1;
@mjdominus
mjdominus / fib.hs
Created March 28, 2011 17:54
fibonacci identity
choose _ 0 = 1
choose 0 _ = 0
choose n k = choose (n-1) (k-1) * n `div` k
pow n 0 = 1
pow n k = n * pow n (k-1)
fib n = theSum `div` pow2
where theSum = sum [ (choose n (2*k+1)) * (pow 5 k) |
k <- [0 .. div (n-1) 2] ]
@mjdominus
mjdominus / minotaur.pl
Created March 29, 2011 15:36
Minotaur catches up to you
sub minotaur_is_here {
local(@parts) = ('poetry',
'arms', 'legs', 'head', 'nose', 'thumbs',
'ears', 'hair', 'skin', 'eyelids', 'face',
);
local($part) = $parts[int(rand(@parts))];
$HEREDESC .= "The MINOTAUR is here! ";
if ($part eq 'poetry') {
@mjdominus
mjdominus / irisdays.pl
Created March 29, 2011 19:03
Obsessive kid-age-calculating program
#!/usr/bin/perl
use Date::Calc ':all';
my @ARG;
if (@ARGV) {
if ($ARGV[0] =~ /^(\d{4})-?(\d{2})-?(\d{2})$/) {
@ARG = ($1, $2, $3);
} else {
my $d = time() + shift() * 86400;
@mjdominus
mjdominus / gist:1095206
Created July 20, 2011 15:43
Biggish SQL query
public Set<PhyloTree> findByTopology3(TaxonVariant a, TaxonVariant b, TaxonVariant c) {
Set<PhyloTree> returnVal = new HashSet<PhyloTree>();
Set<TaxonVariant> aTV = getTaxonLabelHome().expandTaxonVariant(a);
Set<TaxonVariant> bTV = getTaxonLabelHome().expandTaxonVariant(b);
Set<TaxonVariant> cTV = getTaxonLabelHome().expandTaxonVariant(c);
if (aTV.isEmpty() || bTV.isEmpty() || cTV.isEmpty()) {
// XXX This avoids a query syntax error later on but maybe isn't
// the best behavior.
@mjdominus
mjdominus / primes.pl
Created September 16, 2011 20:57
Obfuscated Perl program
# Author: John Tromp <[email protected]>
# http://homepages.cwi.nl/~tromp/cl/cl.html
$|=1; $i=
sub{my$s= shift;
sub{ shift->(
sub{my$n= shift;sub{$n}})->($s)}};$y=
sub{my$a= shift;my$q=
sub{my$t= shift;$a->(
sub{ $t->($t)->(shift)})};$q->($q)};$y->(
sub{my$a= shift;