Skip to content

Instantly share code, notes, and snippets.

View rozap's full-sized avatar

Chris Duranti rozap

View GitHub Profile
@rozap
rozap / ldparse.py
Created October 7, 2016 17:14
parse ldjson
#!/usr/bin/python
import sys
import json
"""
cat ldjson-thing | ldjson msg,time
"""
def pick(row, path, label = ''):
if len(path) == 1:
@rozap
rozap / foo.ex
Last active September 15, 2016 19:49
defmodule Foo do
def to_strings(m) when is_map(m) do
m
|> Enum.map(fn
{k, v} when is_integer(k) -> {Integer.to_string(k), to_strings(v)}
{k, v} -> {k, to_strings(v)}
end)
|> Enum.into(%{})
end
def to_strings(a_list) when is_list(a_list) do
@rozap
rozap / imports2.py
Created July 22, 2016 19:53
use imports2 from python
import urllib3
from urlparse import urlparse
import os
import json
from urllib import urlencode
from time import sleep
import pprint
import argparse
import sys
We can't make this file beautiful and searchable because it's too large.
Police Beat,CRIME_TYPE,CRIME_DESCRIPTION,STAT_VALUE,REPORT_DATE,Sector,Precinct,Row_Value_ID
B1,Homicide,Homicide,0,01/01/2008,B,N,1
B1,Rape,Rape,0,01/01/2008,B,N,2
B1,Robbery,Robbery,5,01/01/2008,B,N,3
B1,Assault,Assault,1,01/01/2008,B,N,4
B1,Larceny-Theft,Larceny-Theft,35,01/01/2008,B,N,5
B1,Motor Vehicle Theft,"Vehicle Theft is theft of a car, truck, motorcycle or any motor vehicle.",4,01/01/2008,B,N,6
B1,Burglary,Burglary,15,01/01/2008,B,N,7
B2,Homicide,Homicide,0,01/01/2008,B,N,8
B2,Rape,Rape,0,01/01/2008,B,N,9
EQUIP_ID YEAR MAKE MODEL COLOR DESCRIPTION AUCTION HOUSE COMMENTS
12909 2001 GMC SAFARI WHITE PASSENGER MINIVAN BIDADOO ONLINE AUCTION
31479 2010 FORD CROWN VICTORIA BLUE/WHITE PATROL CAR MURPHYS AUCTION
31480 2010 FORD CROWN VICTORIA BLUE/WHITE PATROL CAR BIDADOO ONLINE AUCTION
31485 2010 FORD CROWN VICTORIA BLUE/WHITE PATROL CAR BIDADOO ONLINE AUCTION
31489 2010 FORD CROWN VICTORIA BLUE/WHITE PATROL CAR BIDADOO ONLINE AUCTION
31490 2010 FORD CROWN VICTORIA BLUE/WHITE PATROL CAR MURPHYS AUCTION
31493 2010 FORD CROWN VICTORIA BLUE/WHITE PATROL CAR BIDADOO ONLINE AUCTION
31494 2010 FORD CROWN VICTORIA BLUE/WHITE PATROL CAR BIDADOO ONLINE AUCTION
31498 2010 FORD CROWN VICTORIA BLUE/WHITE PATROL CAR - DUI MURPHYS AUCTION TOTALED (4/2016)
foo bar
1 2
defmodule KVStore do
use GenServer
# This executes within the supervisor or whoever starts the KVStore
def start_link do
# First arg is the callback module (this module)
# The name arg registers the process globally as `KVStore`, essentially making it a singleton
GenServer.start_link(KVStore, [], name: KVStore)
end
@rozap
rozap / wtf.md
Last active December 3, 2015 05:52
defimpl Poison.Encoder, for: Usic.User do
  @attributes ~W(id email inserted_at updated_at)a

  def encode(song, _options) do
    song
    |> Map.take(@attributes)
    |> Poison.encode!
  end
end
@rozap
rozap / wat
Created December 3, 2015 05:49
00:47:26.460 [error] GenServer #PID<0.276.0> terminating
** (Poison.EncodeError) unable to encode value: {nil, "user"}
(poison) lib/poison/encoder.ex:339: Poison.Encoder.Any.encode/2
(poison) lib/poison/encoder.ex:213: anonymous fn/4 in Poison.Encoder.Map.encode/3
(poison) lib/poison/encoder.ex:214: Poison.Encoder.Map."-encode/3-lists^foldl/2-0-"/3
(poison) lib/poison/encoder.ex:214: Poison.Encoder.Map.encode/3
(poison) lib/poison/encoder.ex:213: anonymous fn/4 in Poison.Encoder.Map.encode/3
(poison) lib/poison/encoder.ex:214: Poison.Encoder.Map."-encode/3-lists^foldl/2-0-"/3
(poison) lib/poison/encoder.ex:214: Poison.Encoder.Map.encode/3
(poison) lib/poison/encoder.ex:213: anonymous fn/4 in Poison.Encoder.Map.encode/3
def(at(<<var!(head) :: binary - size(2), rest :: binary>>, ptr, meta) when ptr >= 8 and ptr <= 9) do
new_posn = ptr + 2
case({:meta, {:header_length, head}}) do
{:halt, _} = halt ->
halt
{:meta, {key, val}} ->
{rest, new_posn, Dict.put(meta, key, val), []}
result ->
{rest, new_posn, meta, [result]}
end