Skip to content

Instantly share code, notes, and snippets.

View trentonstrong's full-sized avatar

Trent Strong trentonstrong

View GitHub Profile
@trentonstrong
trentonstrong / tree.hs
Created September 6, 2015 02:22
prints a tree from the current dir
import Control.Monad (liftM)
import Data.Tree
import System.Directory (doesDirectoryExist, getDirectoryContents)
import System.FilePath ((</>), takeFileName)
children :: [FilePath] -> [FilePath]
children = filter (\ p -> p /= "." && p /= ".." )
listDirectory :: FilePath -> IO [FilePath]
listDirectory path = liftM children $ getDirectoryContents path
extern crate timely;
use timely::dataflow::*;
use timely::dataflow::operators::{Input, Inspect};
use std::io::{self, BufRead};
fn main() {
// initializes and runs a timely dataflow computation
timely::execute_from_args(std::env::args(), |root| {
@trentonstrong
trentonstrong / epic_debug_sesh.md
Last active August 29, 2015 14:27
epic debug sesh

Our freshly minted Haskell apps running inside Nix closures on AMIs are somehow throwing "Connection refused errors" on addresses and ports that are very much open and telnettable from the machine...

The strace cap

connect(3, {sa_family=AF_INET, sin_port=htons(9092), sin_addr=inet_addr("52.20.114.33")}, 16) = -1 EINPROGRESS (Operation now in progress)
clock_gettime(CLOCK_MONOTONIC, {2267, 491936504}) = 0
select(4, [], [3], NULL, {0, 988827})   = 1 (out [3], left {0, 987760})
getsockopt(3, SOL_SOCKET, SO_ERROR, [0], [4]) = 0
fcntl(3, F_GETFL)                       = 0x802 (flags O_RDWR|O_NONBLOCK)
@trentonstrong
trentonstrong / gist:32aeb43328da018ee1c3
Last active August 29, 2015 14:14
tableau / redshift very inefficient query
EXPLAIN SELECT CAST("optimization_output_flow_view"."destination_site_name" AS TEXT) AS "none_destination_site_name_nk",
CAST("optimization_output_flow_view"."destination_site_type" AS TEXT) AS "none_destination_site_type_nk",
CAST("optimization_output_flow_view"."source_site_name" AS TEXT) AS "none_source_site_name_nk",
SUM("optimization_output_flow_view"."flow_amount") AS "sum_flow_amount_ok",
SUM("optimization_output_flow_view"."flow_cost") AS "sum_flow_cost_ok"
FROM "public"."optimization_output_flow_view" "optimization_output_flow_view"
WHERE(0=1)
GROUP BY 1, 2, 3
HAVING ((SUM("optimization_output_flow_view"."flow_amount") >= 0)
AND (SUM("optimization_output_flow_view"."flow_amount") <= 711859));
### Keybase proof
I hereby claim:
* I am trentonstrong on github.
* I am trentonstrong (https://keybase.io/trentonstrong) on keybase.
* I have a public key whose fingerprint is 0A96 0B07 9436 C9FC 4DDE 05EF 50C2 BF5C 19EA 647F
To claim this, I am signing this object:
/**
* Created with IntelliJ IDEA.
* User: trentstrong
* Date: 12/2/13
* Time: 1:34 PM
* To change this template use File | Settings | File Templates.
*/
public class TestMethodOverride {
public void handleCall(Object o) {
beforeEach(function(done){
// set up pre-existing opportunity
Opportunity(drinksOpp).create(account.uuid, function(err){
if (err) return done(err)
})
var jobTask = { type: 'update-opportunities'
, data: { 'opportunities': [drinksOppNew, burgersOpp]
, 'opal-user-uuid': account.uuid
}
@trentonstrong
trentonstrong / hosts.py
Last active December 18, 2015 05:29
hosts.py A script for retrieving AWS EC2 instance information in a format usable for your /etc/hosts file. Poor man's DNS, anyone? Requires installation of the package 'boto' (pip install boto) and the creation of a ~/.boto configuration file explained here: http://docs.pythonboto.org/en/latest/boto_config_tut.html
#!/usr/bin/env python
"""
Usage: hosts.py [options]
Options:
-h, --help show this help message and exit
-r REGION, --region=REGION
Region (default us-east-1)
"""
(ns okcupidlabs.creeper.opportunities.scoring
(:require [okcupidlabs.creeper.entities :as entities]
[okcupidlabs.creeper.entities.opportunities :as opp-entities]
[okcupidlabs.creeper.utils.time :as time]
[plumbing.graph :as graph]
[cheshire.core :as json]))
(defn haversine
[{lon1 :longitude lat1 :latitude} {lon2 :longitude lat2 :latitude}]
(let [R 6372.8 ; kilometers
(ns okcupidlabs.creeper.opportunities.scoring
(:require [okcupidlabs.creeper.entities :as entities]
[okcupidlabs.creeper.entities.opportunities :as opp-entities]
[plumbing.graph :as graph]
[okcupidlabs.creeper.queries.user :as queries]))
(defn haversine
[{lon1 :longitude lat1 :latitude} {lon2 :longitude lat2 :latitude}]
(let [R 6372.8 ; kilometers
dlat (Math/toRadians (- lat2 lat1))