Skip to content

Instantly share code, notes, and snippets.

Josh Chernoff joshchernoff

Block or report user

Report or block joshchernoff

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View cli.ex
defmodule Sequencer.CLI do
def main(args \\ []) do
if length(args) > 0 do
# Got something from args
IO.inspect(args)
else
# Got something from STDIN
case IO.read(:stdio, :line) do
:eof ->
:ok
View actions
export const sortColumn = column => {
return dispatch => {
return dispatch({
type: "SORT_COLUMN",
...column
});
};
};
export const sortProjects = column => {
View Custom phoenix form input helper
defmodule MyAppWeb.InputHelper do
use Phoenix.HTML
def input(form, field, opts \\ []) do
type = Phoenix.HTML.Form.input_type(form, field)
wrapper_classes = Keyword.get_values(opts, :wrapper_class) ++ ["row", "form-group"]
inputs_classes = Keyword.get_values(opts, :input_class) ++ ["form-control"]
if form.errors[field], do: inputs_classes = inputs_classes ++ ["form-control-dange"]
View webpack.config.js
const path = require('path');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
module.exports = {
entry: {
app: './web/static/js/app.js',
styles: './web/static/css/app.css'
},
output: {
@joshchernoff
joshchernoff / config.yml
Created Apr 1, 2017
Circle Ci failure with phoenix and elixir
View config.yml
version: 2
jobs:
build:
working_directory: ~/digitalcakes
docker:
- image: trenpixster/elixir:1.4.0
- image: postgres:9.5.6
environment:
POSTGRES_USER: ubuntu
steps:
View console
1) test it inserts with a valid changeset (Pricer.Product.PastPriceRecordTest)
test/pricer/product/past_price_record_test.exs:11
** (ArgumentError) unknown field `product_id`. Only fields, embeds and associations (except :through ones) are supported in changesets
stacktrace:
(ecto) lib/ecto/changeset.ex:503: Ecto.Changeset.type!/2
(ecto) lib/ecto/changeset.ex:474: Ecto.Changeset.process_param/8
(elixir) lib/enum.ex:1325: Enum."-map_reduce/3-lists^mapfoldl/2-0-"/3
(ecto) lib/ecto/changeset.ex:450: Ecto.Changeset.do_cast/7
(pricer) lib/pricer/product/past_price_record.ex:15: Pricer.Product.PastPriceRecord.changeset/2
test/pricer/product/past_price_record_test.exs:13: (test)
View gist:5a2b9db03fb529f4bafb89cb529d4107
defmodule Digitalcakes.PostControllerTest do
use Digitalcakes.ConnCase
import Digitalcakes.Factory
alias Digitalcakes.Post
@valid_attrs params_for(:post)
@invalid_attrs %{slug: nil}
test "lists all entries on index", %{conn: conn} do
conn = get conn, post_path(conn, :index)
View A.ex
defmodule A
def init do
collector = spawn(B, :loop, [[], self])
states = [%{"or" => "oregon"}, %{"wa" => "washington"}]
states |> Enum.each(fn (state) ->
send(collector, {:ok, state})
end)
send(collector, :exit)
end
def loop() do
@joshchernoff
joshchernoff / spec.ex
Last active Jan 12, 2017
An idea of how to write specs.
View spec.ex
defmodule Digitalcakes.PostTest do
use Digitalcakes.ModelCase
alias Digitalcakes.Post
import Digitalcakes.Factory
test "changeset with valid attributes" do
changeset = Post.changeset(%Post{}, params_for(:post))
assert changeset.valid?
end
test "changeset validates required attributes" do
@joshchernoff
joshchernoff / mix test
Last active Oct 29, 2016
validate_format does not look to be working.
View mix test
# Note that slug is "$#_asDFDF"
# and should not be valid.
# yet I see that I get an ok on insert.
# FYI I'm using ex_machina thus why you see build/2
1) test changeset is invalid when slug contains restricted characters (Digitalcakes.PostTest)
test/models/post_test.exs:32
match (=) failed
code: {:error, changeset} = Repo.insert(post)
rhs: {:ok,
You can’t perform that action at this time.