Skip to content

Instantly share code, notes, and snippets.

View pdilyard's full-sized avatar

Paul Dilyard pdilyard

  • Atomic Industries
  • Cleveland, OH
View GitHub Profile

Keybase proof

I hereby claim:

  • I am pdilyard on github.
  • I am pdilyard (https://keybase.io/pdilyard) on keybase.
  • I have a public key ASAr36Pnx0QFdZUNCC3TFhty5NsDF5e2ljQVmjhBLSRoqQo

To claim this, I am signing this object:

@pdilyard
pdilyard / queries.ex
Created April 18, 2017 16:46
Query examples
iex(4)> alias DB.{Conversation, Message, Repo, Thought, User}
[DB.Conversation, DB.Message, DB.Repo, DB.Thought, DB.User]
iex(5)> import Ecto.Query
Ecto.Query
# get a convo by ID
iex(6)> conversation = Repo.get(Conversation, 935)
%DB.Conversation{filter_profanity: true,
__meta__: #Ecto.Schema.Metadata<:loaded, "conversations">,
@pdilyard
pdilyard / classes.py
Created April 14, 2017 17:21
ML lifecycle classes
class Trainer:
def start(self, opts):
"""
Load any data that should exist for the lifetime of the entire app.
Nothing here will be taken out of memory until the app stops.
"""
pass
def load(self, opts):
@pdilyard
pdilyard / fix.ex
Created March 14, 2017 19:38
awfulness
conversation_id = 1707
alias DB.{Repo, Message}
import Ecto.Query
messages = Repo.all(from m in Message, where: m.conversation_id == ^conversation_id, order_by: [desc: m.id])
message_id = Enum.at(messages, 0).id
MessageEngine.Timers.AcceptChoices.complete(%{message_id: message_id}, 0, 0)
alias MessageEngine.{Cooldown, Message, Thoughts, Users}
Thoughts.dump(message_id)
@pdilyard
pdilyard / large.erl
Last active March 7, 2017 22:00
Memory usage
#{'__meta__' => #{'__struct__' => 'Elixir.Ecto.Schema.Metadata',
context => nil,
source => {nil,<<"messages_users">>},
state => loaded},
'__struct__' => 'Elixir.DB.MessageUser',
accepting_choices => true,
all_choices => [#{<<"c">> => 129152,<<"nc">> => 129134},
#{<<"c">> => 129152,<<"nc">> => 129154},
#{<<"c">> => 129152,<<"nc">> => 129155},
#{<<"c">> => 129152,<<"nc">> => 129142},
** (Protocol.UndefinedError) protocol String.Chars not implemented for %Postgrex.Query{columns: ["id", "rid", "name", "email", "password", "anonymous", "sample_provider_id", "force_reset", "role", "organization_id", "recovery_code", "recovery_exp", "stripe_customer", "credits", "archived", "inserted_at", "updated_at"], copy_data: false, decoders: [#Function<8.66637582/1 in Postgrex.Types.decoder/2>, #Function<8.66637582/1 in Postgrex.Types.decoder/2>, #Function<8.66637582/1 in Postgrex.Types.decoder/2>, #Function<8.66637582/1 in Postgrex.Types.decoder/2>, #Function<8.66637582/1 in Postgrex.Types.decoder/2>, #Function<8.66637582/1 in Postgrex.Types.decoder/2>, #Function<8.66637582/1 in Postgrex.Types.decoder/2>, #Function<8.66637582/1 in Postgrex.Types.decoder/2>, #Function<8.66637582/1 in Postgrex.Types.decoder/2>, #Function<8.66637582/1 in Postgrex.Types.decoder/2>, #Function<8.66637582/1 in Postgrex.Types.decoder/2>, #Function<8.66637582/1 in Postgrex.Types.decoder/2>, #Function<8.66637582/1 in Postgrex.Typ
@pdilyard
pdilyard / update_vectors.ex
Created February 1, 2017 02:40
Update vectors for all thoughts in a conversation
alias DB.{Repo, Thought, Conversation}
alias Services.ThoughtService
import Ecto.Query
conversation = Repo.get_by(Conversation, observer_slug: "yedO")
thoughts = Repo.all(from t in Thought, where: t.conversation_id == ^conversation.id)
Enum.each(thoughts, &ThoughtService.update_vector/1)
[error] Task #PID<0.1051.0> started from #PID<0.1044.0> terminating
** (MatchError) no match of right hand side value: %{body: "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<InitiateMultipartUploadResult xmlns=\"http://s3.amazonaws.com/doc/2006-03-01/\"><Bucket>remesh-hydrogen-stage</Bucket><Key>images/conversation_covers/1395/xlarge.png</Key><UploadId>IpWM5bYUEz8ojRmFAyvgUXe8o1LtlRKYSOy8rRWJp5qg7vqveG35J4BFphXLzczdHAgQgG.S4R_yPT0PnSMHUhsaqo9WmvWHSTW58Ch7BMfsG0rVHuiNXYZc.lujjk44</UploadId></InitiateMultipartUploadResult>", headers: [{"x-amz-id-2", "osbzAjFfteUoYAtfxdKUNy1tK57pYB9pLpziMfE+1gsSncRpFWVtgga2WcteoOKn/hOGwVVVTLw="}, {"x-amz-request-id", "AC85E8DF53115A15"}, {"Date", "Thu, 12 Jan 2017 19:30:44 GMT"}, {"Transfer-Encoding", "chunked"}, {"Server", "AmazonS3"}], status_code: 200}
(ex_aws) lib/ex_aws/s3/upload.ex:39: ExAws.S3.Upload.initialize!/2
(ex_aws) lib/ex_aws/s3/upload.ex:83: ExAws.Operation.ExAws.S3.Upload.perform/2
(arc) lib/arc/storage/s3.ex:57: Arc.Storage.S3.do_put/3
(elixir) l
@pdilyard
pdilyard / demographic_csv.ex
Last active November 29, 2016 21:54
Get users and their demographics, using user IDs as the key
import ExOrient.DB
# this query needs the group URL
{:ok, users} = command("select expand(inV().in('can_participate')) from has_participant where url = '19XO' limit 1000")
# this query needs the conversation ID
{:ok, demographics} = command("select expand(out('has_participant').out('has_demographic')) from #22:1228 limit 10000")
demos = Enum.map(demographics, fn d ->
{:ok, responses} = command("select expand(out('has_response')) from #{Utils.rid(d)}")