This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defp find_user(params) do | |
if params["login_id"] || params["device_id"] || params["prism_id"] do | |
query = Portmeirion.User.find_query(params) | |
{:ok, result} = Ecto.Adapters.SQL.query(Repo, query, []) | |
row = List.first(result.rows) | |
if row do | |
id = row |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'benchmark' # standard library module | |
def once_yield | |
if block_given? | |
yield | |
end | |
end | |
def once_block(&block) | |
if block |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Q = require 'q' | |
init = () -> | |
console.log 'init' | |
promises = [checkS3FolderExists('MyData1'), checkS3FolderExists('MyData2')] | |
Q.all(promises).then (results)-> | |
console.log 'Done!' | |
console.log results |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |