Skip to content

Instantly share code, notes, and snippets.

View josevalim's full-sized avatar

José Valim josevalim

View GitHub Profile
"foo bar baz"
|> Stream.unfold(fn
"" -> nil;
acc ->
case String.split(acc, " ", parts: 2) do
[left, right] -> {left, right}
[left] -> {left, ""}
end
end)
|> Enum.take(2)
defmodule Rocket.DateTime do
def type, do: :datetime
# Provide our own casting rules.
def cast(string) when is_binary(string) do
# Try to parse different formats here
end
# Datetime itself should also be valid
def cast(%Ecto.DateTime{} = datetime) do
%% -*- erlang-indent-level: 4 -*-
%%
%% %CopyrightBegin%
%%
%% Copyright Ericsson AB 1996-2014. All Rights Reserved.
%%
%% The contents of this file are subject to the Erlang Public License,
%% Version 1.1, (the "License"); you may not use this file except in
%% compliance with the License. You should have received a copy of the
%% Erlang Public License along with this software. If not, it can be
Nonterminals
grammar expr_list
expr container_expr block_expr access_expr
no_parens_expr no_parens_one_expr no_parens_one_ambig_expr
bracket_expr bracket_at_expr bracket_arg matched_expr unmatched_expr max_expr
op_expr matched_op_expr no_parens_op_expr no_parens_many_expr
comp_op_eol at_op_eol unary_op_eol and_op_eol or_op_eol capture_op_eol
add_op_eol mult_op_eol hat_op_eol two_op_eol pipe_op_eol stab_op_eol
arrow_op_eol match_op_eol when_op_eol in_op_eol in_match_op_eol
type_op_eol rel_op_eol
%% When compiled with: erlc +bin_opt_info foo.erl
%%
%% It prints:
%%
%% foo.erl:13: Warning: NOT OPTIMIZED: compiler limitation: instruction {get_map_elements,
%% {f,3},
%% {x,1},
%% {list,[{atom,state},{x,6}]}} prevents delayed sub binary optimization
-module(foo).
defmodule SomeModule do
def start(host, options) do
# We are assuming SomeSup has been already started somewhere
# (ideally in a supervision tree).
{:ok, child_pid} = SomeSup.attach_to(SomeSup, host, options)
end
end
defmodule SomeSup do
use Supervisor
# José Valim <jose.valim@gmail.com>
# http://josevalim.blogspot.com/
# http://www.pagestacker.com/
#
# This render_sibling paste is Rails 2.2 compatible.
# For Rails 2.1 render_sibling, please check here: http://gist.github.com/19674
module RenderSiblingHelper
# What?
#
# ab -n 1000 -c 5 localhost:3000/main/get_with_component
Requests per second: 51.04 [#/sec]
Time per request: 97.969 [ms]
# ab -n 1000 -c 5 localhost:3000/main/get_with_sibling
Requests per second: 57.35 [#/sec]
Time per request: 87.188 [ms]
# ab -n 1000 -c 5 localhost:3000/main/get_with_partial
Requests per second: 59.04 [#/sec]
# José Valim <jose.valim@gmail.com>
# http://josevalim.blogspot.com/
# http://www.pagestacker.com/
#
# This render_sibling paste is Rails 2.1 compatible.
# For Rails 2.2 render_sibling, please check here: http://gist.github.com/19631
module RenderSiblingHelper
# What?
#
diff --git a/actionpack/lib/action_controller/routing/route_set.rb b/actionpack/lib/action_controller/routing/route_set.rb
index ff44849..f3a4f09 100644
--- a/actionpack/lib/action_controller/routing/route_set.rb
+++ b/actionpack/lib/action_controller/routing/route_set.rb
@@ -170,18 +170,24 @@ module ActionController
def #{selector}(*args)
#{generate_optimisation_block(route, kind)}
+ locale = #{route.segment_keys.include?(:locale) ? '{ :locale => I18n.locale || I18n.default_locale }' : '{}'}
+