Skip to content

Instantly share code, notes, and snippets.


Peter Marreck pmarreck

  • formerly, and currently a contractor
  • Long Island, NY
  • Sign in to view email
View GitHub Profile
pmarreck / procedural_vs_functional.exs
Created Feb 8, 2018
Trying to convert a procedural algorithm into an Elixir functional one.
View procedural_vs_functional.exs
defmodule OutcomesProcedural do
def partitions(cards, subtotal) do
for i <- 0..9, elem(cards,i)>0 do
case subtotal+i+1 do
x when x > 21 -> 0
x when x==21 -> 1
x when x < 21 -> 1+partitions(put_elem(cards, i, elem(cards,i)-1), x)
pmarreck / brunch-config.js
Created Jan 10, 2018
My working brunch-config.js
View brunch-config.js
exports.config = {
// See for docs.
files: {
// javascripts: {
// joinTo: {
// "js/app.js": '*.min.js'
// }
// },
// stylesheets: {
// // joinTo: 'css/app.css',
pmarreck / instructions.bash
Last active Oct 29, 2017
How to get Erlang, Elixir, Phoenix and Postgres set up on a new blank Ubuntu ( project/VM
View instructions.bash
# I had some issues with this and finally culled together instructions from various sites which finally worked
# The first thing you should do is clone your Phoenix/Elixir repo from Github to a blank Ubuntu VM
# The next thing we have to do is remove the stock Erlang which is erlang-base-hipe and not esl-erlang
# (this causes problems later on otherwise)
# But first we will add a new apt source
sudo dpkg -i erlang-solutions_1.0_all.deb
rm erlang-solutions_1.0_all.deb # shouldn't need it anymore
pmarreck / for_all_the_things.exs
Created Oct 9, 2017
Examples of various uses of the "for" syntax in Elixir
View for_all_the_things.exs
# A list generator:
iex> for n <- [1, 2, 3, 4], do: n * 2
[2, 4, 6, 8]
# A comprehension with two generators
iex> for x <- [1, 2], y <- [2, 3], do: x * y
[2, 3, 4, 6]
# A comprehension with a generator and a filter
iex> for n <- [1, 2, 3, 4, 5, 6], rem(n, 2) == 0, do: n
pmarreck / ecto_postgres_fulltext_search_querying_example.ex
Last active Jul 14, 2020
How to set up postgres fulltext search triggers, index, and tsvector column on Elixir/Phoenix, with Ecto querying, including ranking and sorting by rank
View ecto_postgres_fulltext_search_querying_example.ex
defmodule YourAppName.Search do
# ...
@doc """
Queries listings.
def query_listings(query, current_user) do
default_scope = from l in Listing, where: l.draft == false or l.user_id == ^, order_by: [desc: l.updated_at], limit: 50
id = _try_integer(query)
pmarreck / implode_bloatware.ps1
Created Sep 29, 2017
windows powershell bloatware removal script
View implode_bloatware.ps1
get-appxpackage messaging | remove-appxpackage
get-appxpackage sway | remove-appxpackage
get-appxpackage commsphone | remove-appxpackage
get-appxpackage windowsphone remove-appxpackage
get-appxpackage phone | remove-appxpackage
get-appxpackage communicationsapps | remove-appxpackage
get-appxpackage people | remove-appxpackage
get-appxpackage zunemusic | remove-appxpackage
get-appxpackage zunevideo | remove-appxpackage
get-appxpackage zune | remove-appxpackage
pmarreck / actualbiblethings.txt
Created Sep 28, 2017
Uncomfortable Bible Passages
View actualbiblethings.txt
"When a woman has a discharge, if her discharge in her body is blood, she shall continue in her menstrual impurity for seven days; and whoever touches her shall be unclean until evening. Everything also on which she lies during her menstrual impurity shall be unclean, and everything on which she sits shall be unclean." Leviticus 15: 19-20
"When men fight with one another, and the wife of the one draws near to rescue her husband from the hand of him who is beating him, and puts out her hand and seizes him by the private parts, then you shall cut off her hand." Deuteronomy 25:11-12
"Now therefore, kill every male among the little ones, and kill every woman who has known man intimately. But all the girls who have not known man intimately, spare for yourselves." Numbers 31:17-18
"You may purchase male or female slaves from among the foreigners who live among you. You may also purchase the children of such resident foreigners, including those who have been born in your land. You may treat them as your property, pa
pmarreck / migrations_in_console_cheatsheet.exs
Created Sep 25, 2017
How to run Ecto migrations in Elixir/Phoenix from an `iex -S mix` or production console
View migrations_in_console_cheatsheet.exs
# How to run Ecto migrations from IEx console... Examples
# preliminaries assumed in the following code, change to fit your environment:
alias YourAppName.Repo
your_app_name_as_atom = :mpnetwork
downto_version = 20170724182558
# Down:, "priv/repo/migrations/", :down, [to: downto_version])
pmarreck / broadcast_controller_test.exs
Created Jul 29, 2017
reusing a perfectly-set-up conn in phoenix
View broadcast_controller_test.exs
# ...
test "deletes chosen broadcast", %{conn: fresh_conn} do
conn = fresh_conn
broadcast = fixture(:broadcast)
conn = delete conn, broadcast_path(conn, :delete, broadcast)
assert redirected_to(conn) == broadcast_path(conn, :index)
refute Repo.get(Broadcast,
assert_error_sent 404, fn ->
conn = fresh_conn
pmarreck / enum_maps.ex
Created Jul 19, 2017
trying to use ecto_enum...
View enum_maps.ex
defmodule Mpnetwork.EnumMaps do
import EctoEnum
# Housing Class Types
@class_types_int ~w[residential condo co_op hoa rental land com_ind]a
def class_types_int, do: @class_types_int
@class_types_ext ~w[Residential Condo Co-op HOA Rental Land Commercial/Industrial]
# def class_types_ext, do: @class_types_ext
You can’t perform that action at this time.