This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def loop(socket) do | |
case socket |> Socket.Web.recv! do | |
{:text, data} -> | |
# process data | |
loop(socket) | |
{:ping, _ } -> | |
socket |> Socket.Web.send!({:pong, ""}) | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'benchmark/ips' | |
require 'readthis' | |
cache = Readthis::Cache.new(namespace: 'rd', expires_in: 60) | |
range = ('a'..'z').to_a | |
range.each { |key| cache.write(key, key) } | |
Benchmark.ips do |x| | |
x.report 'read_multi:standard' do |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for adapter <- [Memory, Redis] do | |
@adapter adapter | |
setup_all do | |
Application.put_env(:flippant, :adapter, @adapter) | |
Application.ensure_started(:flippant) | |
on_exit fn -> | |
Application.stop(:flippant) | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Skylight | |
module Normalizers | |
class Knuckles < Normalizer | |
register 'knuckles.stage' | |
CAT = 'app.knuckles.pipeline'.freeze | |
def normalize(trace, name, payload) | |
stage = payload[:stage] | |
title = stage.sub(/^Knuckles::(Stages::)?/, '') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
* `valid?` - Stores if the changeset is valid | |
- * `model` - The changeset root model | |
+ * `data` - The changeset source data, for example, a struct | |
* `params` - The parameters as given on changeset creation | |
* `changes` - The `changes` from parameters that were approved in casting | |
* `errors` - All errors from validations | |
* `validations` - All validations performed in the changeset | |
* `constraints` - All constraints defined in the changeset | |
* `required` - All required fields as a list of atoms | |
- * `optional` - All optional fields as a list of atoms |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule MyApp.EmailView do | |
use MyApp.Web, :view | |
def render(template, format, %{assigns: assigns}) do | |
rendered = render_to_string(__MODULE__, template, assigns) | |
case format do | |
:text -> rendered | |
:html -> Earmark.to_html(rendered) | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def normalize(email) do | |
%{email | from: normalize(email.from, :from), | |
to: normalize(List.wrap(email.to), :to), | |
cc: normalize(List.wrap(email.cc), :cc), | |
bcc: normalize(List.wrap(email.bcc), :bcc)} | |
end | |
defp normalize(record, type) do | |
Formatter.format_email_address(record, %{type: type}) | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmacro __using__(opts) do | |
quote bind_quoted: [opts: opts] do | |
%{adapter: adapter, config: config} = Bamboo.Mailer.parse_opts(__MODULE__, opts) | |
@adapter adapter | |
@config config | |
end | |
end | |
def start_link(opts \\ []) do |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# SELECT depname, empno, salary, avg(salary) OVER (PARTITION BY depname) FROM empsalary; | |
from e in MyApp.EmpSalaray, | |
select: [e.depname, e.empno, e.salary, avg(e.salary)], | |
over: partition_by(e.depname) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defp run_query(opts, sql) do | |
opts = Keyword.put(opts, :database, "template1") | |
parent = self() | |
{:ok, conn} = Connection.connect(opts) | |
spawn fn -> | |
value = try do | |
Connection.query(conn, sql, [], []) |