Skip to content

Instantly share code, notes, and snippets.

View favila's full-sized avatar

Francis Avila favila

View GitHub Profile
@favila
favila / 113-congress-agency-mentions.txt
Created March 15, 2013 19:00
List of agencies mentioned in 113th congress bills
NIST name
1600 Department of Labor
7529 National Institutes of Health
7500 Department of Health and Human Services
7000 Department of Homeland Security
1500 Department of Justice
1100 Executive Office of the President
1524 Drug Enforcement Administration
1560 Bureau of Alcohol, Tobacco, Firearms and Explosives
2400 Office of Personnel Management
@favila
favila / bill-agency-reference-counts
Created March 15, 2013 19:54
List of agencies and their count of references. Data is from deepbills.dancingmammoth.com/downloads. Includes only "complete" bills (all tagging done) where the agency is mentioned more than once.
<bills>
<bill id="113hr51ih">
<agency id="1600" count="6" name="Department of Labor"/>
</bill>
<bill id="113hr80ih">
<agency id="7529" count="4" name="National Institutes of Health"/>
<agency id="7500" count="3" name="Department of Health and Human Services"/>
</bill>
<bill id="113hr57ih"/>
<bill id="113hr72ih">
@favila
favila / qnamemap.py
Created March 19, 2013 08:12
Helper class for dealing with namespaces in elementtree (or any other situation where clark notation is used for qnames).
import re
# regular expressions for chars in an NCName
rCHARS = {
'startchar': u"_a-zA-Z"
u"\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-"
u"\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-"
u"\uFFFD\u10000-\uEFFFF",
'char': u"0-9\u00B7\u0300-\u036F\u203F-\u2040.-",
}
@favila
favila / flatten.php
Created March 19, 2013 08:19
Braindump of a whole bunch of ways to flatten an array in PHP (with timing harness)
<?php
function flatten_for($arr) {
$c = count($arr);
$newarr = array();
for ($i = 0; $i < $c; $i++) {
$newarr[] = $arr[$i][0];
}
return $newarr;
}
@favila
favila / MultiIndex.php
Created April 4, 2013 01:36
`MultiIndex` class: simple class for keeping multiple indexes on an array of items with easy derived sorting. Originally written to answer [this stackoverflow question](http://stackoverflow.com/q/15800052/1002469).
class MultiIndex {
protected $array;
protected $indexes = array();
protected $indexdefs = array();
function __construct($array, $indexdefs)
{
$this->array = $array;
$this->indexdefs = $indexdefs;
@favila
favila / ci_lower_bound.sql
Last active July 24, 2022 17:41 — forked from anonymous/ci_lower_bound.sql
MySQL stored functions for calculating confidence intervals using Wilson scores: more precisely "Lower bound of Wilson score confidence interval for a Bernoulli parameter". Includes a P(qn) function (inverse normal distribution). See http://www.evanmiller.org/how-not-to-sort-by-average-rating.html This describes a way to rank items based on a ve…
# Francis Avila 2009-07-04
# See http://www.evanmiller.org/how-not-to-sort-by-average-rating.html
# These functions calculate "Lower bound of Wilson score confidence interval for a Bernoulli parameter"
# Two stored functions:
# CI_LOWER_BOUND(pos, trials, confidence) calculate a wilson score given POS positive votes in TRIALS number of trials
# PNORM(qn) calculate P(qn) (inverse normal distribution); needed by CI_LOWER_BOUND
delimiter ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `ci_lower_bound`(pos INTEGER, trials INTEGER, confidence DOUBLE) RETURNS double
NO SQL
@favila
favila / imgmeta.java
Created May 13, 2013 04:17
Sample code demonstrating how to parse the XMP metadata in an image using javax.imageio.metadata. Written to answer this stackoverflow question: http://stackoverflow.com/a/13748517/1002469
import java.io.*;
import java.util.*;
// for imageio metadata
import javax.imageio.*;
import javax.imageio.stream.*;
import javax.imageio.metadata.*;
// for xml handling
import org.w3c.dom.*;
@favila
favila / b64longs.clj
Created August 7, 2013 02:12
Encode and Decode java.lang.Long as a web-safe, identically-sortable Base64 string. I.e., the Long and the string will both sort exactly the same way, and none of the characters of the string ever need to be escaped in a web context (e.g. in html, in xml, in any part of a url). Requires net.iharder.Base64 class which is Public Domain. See http:/…
(ns b64longs
"Encode and Decode java.lang.Long as a web-safe, identically-sortable Base64 string.
I.e., the Long and the string will both sort exactly the same way, and none of
the characters of the string ever need to be escaped in a web context (e.g. in html,
in xml, in any part of a url).
Requires net.iharder.Base64 class which is Public Domain.
See http://iharder.sourceforge.net/current/java/base64/
Add this as a leinigen dependency.
@favila
favila / subclass.cljs
Last active December 20, 2015 20:19
Attempts at creating clean subclasses (with closure compiler annotations) in clojurescript with macros
(ns subclass
(:require [clojure.string :as string]))
;;TODO: definterface
; :closure/const
; :const
; :closure/constructor
; :closure/depreciated
@favila
favila / parallel-chan-map.clj
Created September 19, 2013 14:32
parallel-chan-map: Read in-chan and put result of `(apply f in-chan-value args)` on out-chan, running items in "parallel" and yielding results out-of-order. Works with Clojure or Clojurescript.
(ns parallel-chan-map
(:require-macros [cljs.core.async.macros :refer (go alt!)])
(:require [cljs.core.async :refer (>! close! put! chan )]))
(defn parallel-chan-map
"Read in-chan and put result of `(apply f in-chan-value args)` on out-chan,
potentially running items in parallel and yielding results out-of-order.
Function f must return something takeable (e.g. a go-block, channel, promise),
in essence spawning a \"subprocess\" which this function manages as a pool