Skip to content

Instantly share code, notes, and snippets.


Paul Smith paulcsmith

View GitHub Profile
class Home::IndexPage < MainLayout
def content
Kilt.embed "my_page.slang", io_name: @view
paulcsmith /
Last active Mar 8, 2018
For sign up and sign in (authentication)
class Somethings::Index < BrowserAction
before require_sign_in
action { "do stuff" }
# You can extract all this to a module since you'll likely use it in multiple places
# Probably in src/pipes/ or something
private def require_sign_in
if signed_in?
paulcsmith / hello world benchmark
Last active Dec 4, 2017
Lucky hello world benchmark 0.6.1
View hello world benchmark
% wrk -t4 -c100 -d30S --timeout 2000 http://localhost:8080
Running 30s test @ http://localhost:8080
4 threads and 100 connections
Thread Stats Avg Stdev Max +/- Stdev
Latency 1.89ms 481.91us 14.54ms 93.89%
Req/Sec 13.41k 1.90k 14.70k 90.08%
1601002 requests in 30.00s, 299.26MB read
Requests/sec: 53358.67
Transfer/sec: 9.97MB
paulcsmith /
Last active Nov 21, 2017
Testing Lucky apps
# spec/support/
require "http/client"
class AppConn
getter! response
@response : HTTP::Client::Response? = nil
module Matchers
def contain_html(html : String)
paulcsmith / test.exs
Last active Jul 13, 2016
ExMachina 2.0?
View test.exs
defmodule MyApp.Factory do
def user_factory do
email: "",
name: "Paul"
# Makes it easy to organize factories however you want
paulcsmith / mime type of file
Created Jun 22, 2016
How to get mime type for a file
View mime type of file
$ file -I Makefile
Makefile: text/x-makefile; charset=us-ascii
paulcsmith / brunch-config.js
Created Apr 27, 2016
Phoenix brunch set up
View brunch-config.js
var bourbonPath = require("bourbon").includePaths[0];
exports.config = {
// See for docs.
files: {
javascripts: {
joinTo: "js/app.js"
// To use a separate vendor.js bundle, specify two files path
paulcsmith / gist:41f22e8210efa028dda2
Created Feb 13, 2016
Tracing function calls in Elixir with dbg
View gist:41f22e8210efa028dda2
:dbg.p :all, :c
:dbg.tpl ModuleToTrace, :x
View changeset.ex
defmodule MyApp.Changeset do
def cast(model_or_changeset, :empty, required, optional) do
Ecto.Changeset.cast(model_or_changeset, :empty, required, optional)
def cast(model_or_changeset, params, required, optional) do
param_keys = params |> Map.keys |>
allowed_params = (required ++ optional) |>
disallowed_params = param_keys -- allowed_params
paulcsmith / time.ex
Last active Feb 4, 2016
Casting/Converting time zones
View time.ex
|> Timex.DateTime.parse("{ISO}")
|> Timex.DateConvert.to_erlang_datetime
# You probably don't need this next line for most things in Ecto.
# Changesets and queries automatically cast erlang timestamps
|> Ecto.DateTime.from_erl