Skip to content

Instantly share code, notes, and snippets.

View moxley's full-sized avatar

Moxley Stratton moxley

View GitHub Profile
@moxley
moxley / shakespeare.txt
Created October 6, 2018 17:38
Machine Learning generated "Shakespeare" text
QUEEN:
Good my lord, be not angry with the streets,
And then remove the breath of mine, yet I know no less.
KING EDWARD IV:
What means the cause why must I call thee fare?
Where is the prince your son, I pray you, sir, how shall the old man of my son,
And leave the blood of English shames the crown,
Which then betimes abroad shall be thy grief,
That thou hast the devil through the court, they will tell you both
@moxley
moxley / big-elixir.exs
Created September 23, 2018 05:34
Concatenated ball of Elixir
This file has been truncated, but you can view the full file.
defmodule Absinthe.Mixfile do
use Mix.Project
@version "1.5.0-dev"
def project do
[
app: :absinthe,
version: @version,
elixir: "~> 1.4",
@moxley
moxley / hello.ex
Last active September 23, 2018 04:28
hello module
defmodule Phoenix do
use Application
def start(_type, _args) do
_ = Phoenix.Template.engines()
_ = Phoenix.Template.format_encoder("index.html")
warn_on_missing_json_library()
if stacktrace_depth = Application.get_env(:phoenix, :stacktrace_depth) do
:erlang.system_flag(:backtrace_depth, stacktrace_depth)
@moxley
moxley / fuckdocker_fn.sh
Created November 30, 2017 19:17
Kill all the docker artifacts
function fuckdocker() {
make stop
docker kill `docker ps -a -q`
docker rm `docker ps -a -q`
docker rmi -f `docker images -q`
docker volume rm -f `docker volume ls -q`
docker network rm -f `docker network ls -q`
docker service rm `docker service ls -q`
}
@moxley
moxley / easy_query_test.exs
Created July 15, 2016 23:15
Test easy query DSL
defmodule DynaQuery.EasyTest do
use ExUnit.Case, async: true
require Ecto.Query
alias Ecto.Query, as: Q
alias Haas.HomeAssessment
alias Haas.HomeAssessmentSponsor
alias Haas.HomePaint
alias DynaQuery.Easy
alias DynaQuery.Easy.Table
@moxley
moxley / build_query_test.exs
Created July 15, 2016 23:14
Build query dynamically
test "query with multiple WHEREs" do
query =
Easy.from({HomeAssessment, :ha})
|> Easy.where({:>=, [ha: :id], 1})
|> Easy.where({:<=, [ha: :id], 10})
|> Easy.build_query
assert inspect(query) == inspect(Q.from(ha in HomeAssessment, where: ha.id >= 1, where: ha.id <= 10))
end
@moxley
moxley / join_test.exs
Created July 15, 2016 22:39
Showing there is no way to dynamically build an Ecto query where the schemas involved and number of joins are only known at runtime
defmodule MyApp.JoinTest do
def add_join(query, qual, join_schema, join_key, _other_schema, other_key) do
# -------------------------->| |<-------------------------- #
Ecto.Query.join(query, qual, [t0], t1 in ^(join_schema), field(t1, ^join_key) == field(t0, ^other_key))
# -------------------------->| |<-------------------------- #
end
test "add_join" do
query =
Ecto.Query.from(Cart)
@moxley
moxley / strip_ecto_record.exs
Created March 31, 2016 23:32
Strip an Ecto record of attributes that cannot be encoded to JSON
record = Enum.reduce(Map.keys(record), %{}, fn (key, map) ->
value = Map.get(record, key)
key_to_add = cond do
is_map(value) && Map.get(value, :__struct__, nil) == Elixir.Ecto.Association.NotLoaded ->
nil
key == :__meta__ ->
nil
key == :__struct__ ->
nil
@moxley
moxley / bash_arg_parsing.sh
Created September 14, 2015 22:53
Bash function for parsing script arguments for passing to sub command and sub-sub-command
# Flexible argument parsing
#
# Example:
# Command:
# ```
# ./docker/script --env=APP_ENV=development -v $(pwd)/foo:/foo docker.househappy.org/datafeed ./bin/run "puts 'hello'"
# ```
#
# Script:
# ```
@moxley
moxley / process_container_args.sh
Created September 11, 2015 17:15
Bash function to process script args to pass to a docker sub command
# ./script --env=RAILS_ENV=production --rm -- bundle exec rails c
# DOCKER_ARGS:
# --env=RAILS_ENV=production
# --rm
# PROCESS_CMD: bundle exec rails c
function process_container_args {
DOCKER_ARGS=()
PROCESS_CMD=()
_state=DOCKER_ARGS