Skip to content

Instantly share code, notes, and snippets.

View apendleton's full-sized avatar

Andrew Pendleton apendleton

  • Mapbox
  • Washington, DC
View GitHub Profile
var ocemail = function(url, domain) {
var capitalize = function(s) { return s.charAt(0).toUpperCase() + s.slice(1).toLowerCase(); }
// url parser from http://jsperf.com/url-parsing
var urlParseRE = /^(((([^:\/#\?]+:)?(?:(\/\/)((?:(([^:@\/#\?]+)(?:\:([^:@\/#\?]+))?)@)?(([^:\/#\?\]\[]+|\[[^\/\]@#?]+\])(?:\:([0-9]+))?))?)?)?((\/?(?:[^\/\?#]+\/+)*)([^\?#]*)))?(\?[^#]+)?)(#.*)?/;
var hostname = urlParseRE.exec(url)[11];
if (hostname) {
var domainMatch = /^(?:www[.])?([-a-z0-9]+)[.](house|senate)[.]gov$/;
var match = domainMatch.exec(hostname.toLowerCase());
use std::num::pow;
pub struct Point { x: int, y: int }
struct Line { p1: Point, p2: Point }
impl Line {
pub fn length(&self) -> f64 {
let xdiff = self.p1.x - self.p2.x;
let ydiff = self.p1.y - self.p2.y;
((pow(xdiff, 2) + pow(ydiff, 2)) as f64).sqrt()