Skip to content

Instantly share code, notes, and snippets.

@sillypog
sillypog / major_us_city_dma_codes.py
Created November 15, 2012 17:59 — forked from ecarter/major_us_city_dma_codes.py
Major US Cities with Latitude/Longitude and DMA Codes
# Major US Cities with DMA Codes
major_cities = [
{'city': 'Ada', 'dma_code': 657, 'latitude': 34.774531000000003, 'longitude': -96.678344899999999, 'region': 'OK', 'slug': 'ada-ok'},
{'city': 'Akron', 'dma_code': 510, 'latitude': 41.081444699999999, 'longitude': -81.519005300000003, 'region': 'OH', 'slug': 'akron-oh'},
{'city': 'Albany', 'dma_code': 525, 'latitude': 31.578507399999999, 'longitude': -84.155741000000006, 'region': 'GA', 'slug': 'albany-ga'},
{'city': 'Alexandria', 'dma_code': 644, 'latitude': 31.311293599999999, 'longitude': -92.445137099999997, 'region': 'LA', 'slug': 'alexandria-la'},
{'city': 'Alpena', 'dma_code': 583, 'latitude': 45.061679400000003, 'longitude': -83.432752800000003, 'region': 'MI', 'slug': 'alpena-mi'},
{'city': 'Altoona', 'dma_code': 574, 'latitude': 40.5186809, 'longitude': -78.394735900000001, 'region': 'PA', 'slug': 'altoona-pa'},
{'city': 'Amarillo', 'dma_code': 634, 'latitude': 35.221997100000003, 'longitude': -101.8312969, 'region': 'TX', 'slug': 'amarillo-tx'},
@sillypog
sillypog / gist:d010f5c314dc717e5ed1
Created November 19, 2014 19:25
Bluegreen socialarticle results 11/19/14
prod_prism=# SELECT variation, action, count(action) as total FROM production_campaigns WHERE campaign_type='bluegreen' GROUP BY variation, action;
variation | action | total
-----------+---------------+----------
blue | impression | 17434052
green | impression | 602006
| impression | 355
blu | impression | 3
3 | impression | 3
bl | conversion | 1
blue | conversion | 4221029
Q = require 'q'
init = () ->
console.log 'init'
promises = [checkS3FolderExists('MyData1'), checkS3FolderExists('MyData2')]
Q.all(promises).then (results)->
console.log 'Done!'
console.log results
recon:click:1439948225:my-starred-stories:app-stream:2550806+2548981+2550020+2549209+2549979+2549296+2549224+2549014+2549003+2549120+2548767+2548338+2548374+2547798+2548224+2547752+2547872+-415623+2547773+2547673+2547137+2547410+2547206+-405121+-400699+2539912+2543910+2546320+2546026+2546371+2546405+-391261+2546033+2545482+2545316+2545138+2544480+2545039+2544374+2544688+2544680+2543838+2543686+2543691+2543579+2543092+2543393+2542784+2539908+2542248+2541624+2541290+2534648+2536843+2540352+2540322+2540318+2540320+2539519+2539327+2539200+2539034+2531999+2538782+2538762+2535644+2537233+2537216+2536625+2535130+2535196+2533855+2533902+2534846+2534225+2534257+2534107+2534109+2533247+2533244+2529995+2532366+2531568+2529784+2529783+2528962+2528899+2526418+2522718+2525418+2525416+2525410+2525412+2525283+2523945+2525176+2525181+2525180+2524703+2522528+2523832+2523218+2521417+2523221+2521769+2521889+2520159+2519981+2519984+2519170+2518987+2518661+2518716+2518685+2518670+2518692+2518148+2517266+2517267+2517051+2517053+251
class AbstractDimensionTable
def self.call_remote_cache(fields)
Cache.fetch(table_name, fields) do
call_redshift fields
end
end
end
class Cache
def self.fetch(table_name, fields, &block)
class Cache
def self.fetch(table_name, fields, &block)
result = redis.get(table_name + ':' + fields.values.join('|'))
unless result
# block allows us to try to look for the value elsewhere, if requested
# NOTE: we are not currently passing a block, so this syntax is sufficiently fast
# However, when a block is present it is faster to use block_given? and yield
if block
result = block.call
require 'benchmark' # standard library module
def once_yield
if block_given?
yield
end
end
def once_block(&block)
if block
@sillypog
sillypog / identify_controller.ex
Last active December 2, 2016 20:39
Portmeirion.IdentifyController V1
defp find_or_create_user(params) do
user = find_user_by_login(params) || find_user_by_device(params) || find_user_by_prism(params)
...
end
defp find_user_by_login(%{"login_id" => login_id}), do: Repo.get_by(Portmeirion.User, %{login_id: login_id})
defp find_user_by_login(_), do: nil
defp find_user_by_device(%{"device_id" => device_id}) do
Repo.one(
@sillypog
sillypog / identify_controller.ex
Last active November 30, 2016 01:16
Portmeirion.IdentifyController V2
defp find_user(params) do
if params["login_id"] || params["device_id"] || params["prism_id"] do
from(u in Portmeirion.User, limit: 1, select: %{warehouse_id: u.warehouse_id})
|> join_device_clause(params)
|> where_clause(params)
|> order_clause(params)
|> Repo.one
else
nil
end
@sillypog
sillypog / identify_controller.ex
Last active November 30, 2016 01:16
Portmeirion.IdentifyController V3
defp where_clause(query, params) do
# Get just the credentials params from the full params - can I use a struct for that?
# Turn that into a key value list
# Pass to a where_fragment method that matched on list length
# Return fragment of appropriate size
allowed_params = ~w(login_id facebook_id device_id prism_id)
key_values = params
|> Enum.filter(fn({key, _}) -> Enum.member?(allowed_params, key) end)
|> Enum.map(fn({key, value}) -> [String.to_existing_atom(key), cast_param(key, value)] end)