Skip to content

Instantly share code, notes, and snippets.

defmodule Brando.Form.UserForm do
use Brando.Form
import Brando.Router.Helpers
def get_status_choices do
[[value: "0", text: "Choice 1"],
[value: "1", text: "Choice 2"]]
end
form "user", [method: "POST", action: admin_user_path(:create)] do
# increase the stacktrace depth
:erlang.system_flag(backtrace_depth, n)
<%= render MyApp.SomeView, "sometemplate.html", user: @user %>
# all parent assigns
<%= render MyApp.SomeView, "sometemplate.html", assigns %>
@twined
twined / phoenix_pagination.ex
Last active August 29, 2015 14:11
Phoenix Pagination
# in template
<%= next_page_path({:user_path, [:index]}, @current_page, @conn.params %>
# in view
def next_page_path({cur_path, helper_args}, cur_page, params \\ []) do
params = Dict.merge(params, %{"page" => cur_page + 1})
apply(MyApp.Router.Helpers, cur_path, helper_args ++ [params])
end
@twined
twined / phoenix_i18n_urls.ex
Last active August 29, 2015 14:11
phoenix i18n urls
for locale <- ["en", "fr"] do ... get "/#{I18n.t(locale, "routes.users")"
iex(14)> :dbg.tracer
{:ok, #PID<0.109.0>}
iex(15)> :dbg.p :all, :c
{:ok, [{:matched, :nonode@nohost, 39}]}
iex(16)> :dbg.tpl Z, :x
{:ok, [{:matched, :nonode@nohost, 4}, {:saved, :x}]}
iex(17)> struct(Z, Map.from_struct(%V{})
...(17)> )
@twined
twined / pngquant
Last active August 29, 2015 14:10
# install libpng15
# ----------------
./configure --prefix=/usr/local/libpng
make check
sudo make install
make check
#
sudo updatedb
@twined
twined / _more.scss
Created July 5, 2011 16:13 — forked from idan/_more.scss
More is Less
$less-column-width: 68px;
$less-gutter-width: 24px;
@function column-width($columns) {
@return ($less-column-width * $columns) + ($less-gutter-width * ($columns - 1));
}
@function grid-padding-px($columns) {
@if $columns == 10 {
@return 48px;