This file contains 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 Toolkit.RedisLock do | |
@moduledoc """ | |
Provide mechanism to lock and check locking of a given key. | |
When set lock on a key, must set expiration time to make sure no lock live forever | |
""" | |
@redix_conn :octosells_cache | |
@doc """ | |
Lock given key for `lock_duration` in second. Default lock duration is 5 minute | |
This function make sure only one process can acquire lock. We use `INCR` command to guarantee this. |
This file contains 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 Solid.Parser.Base do | |
defmacro __using__(opts) do | |
custom_tags = Keyword.get(opts, :custom_tags, []) | |
custom_tag_modules = Enum.filter(custom_tags, &is_tuple(&1)) | |
custom_tag_names = custom_tags -- custom_tag_modules | |
quote location: :keep do | |
import NimbleParsec | |
alias Solid.Parser.{Literal, Variable, Argument} |
This file contains 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 Magik.Crypto do | |
@moduledoc """ | |
Provide some basic encrypt/decrypt function | |
""" | |
@aad "AES256GCM" | |
@block_size 16 | |
@doc """ | |
`generate_secret` |
This file contains 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.JsonView do | |
defmacro __using__(_) do | |
quote do | |
def render_json(struct, fields, custom_fields, relationships) do | |
MyApp.JsonView.render_json(struct, __MODULE__, | |
fields: fields, | |
custom_fields: custom_fields, | |
relationships: relationships | |
) | |
end |
This file contains 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
window.Box = (function(){ | |
var template = ` | |
<div tabindex="-1" role="dialog" class="modal modal-{type} {class-modal} fade"> | |
<div class="modal-dialog modal-{size}"> | |
<div class="modal-content"> | |
<div class="modal-header text-inverse {class-header}"> | |
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button> | |
<h5 class="modal-title" >{title}</h5> | |
</div> |
This file contains 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 PhoenixCache.Plug.Cache doimport Plug.Conn | |
# 6 minute | |
@default_ttl 6 * 60 | |
def init(ttl \\ nil), do: ttl | |
def call(conn, ttl \\ nil) do | |
ttl = ttl || @default_ttl | |
# Chỉ cache với GET requestif conn.method == "GET" do# tạo key từ request path và query param, thông thường# thì cùng path và cùng param thì kết quả là giống nhau | |
key = "#{conn.request_path}-#{conn.query_string}" | |
case PhoenixCache.Bucket.get(key) do | |
{:ok, body} -> |
This file contains 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 PhoenixCache.Bucket do | |
use GenServer | |
alias :ets, as: Ets | |
@expired_after 6 * 60 | |
def start_link(args \\ []) do | |
GenServer.start_link(__MODULE__, args, name: __MODULE__) | |
end |
This file contains 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 Infra.Paginator do | |
import Ecto.Query | |
alias Infra.Repo | |
defstruct [:entries, :page, :size, :total] | |
def new(query, params) do | |
page_number = params |> Map.get("page", 1) |> to_int | |
page_size = params |> Map.get("size", 10) |> to_int | |
%Infra.Paginator{ |
This file contains 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
function stringToSlug(str) { | |
// remove accents | |
var from = "àáãảạăằắẳẵặâầấẩẫậèéẻẽẹêềếểễệđùúủũụưừứửữựòóỏõọôồốổỗộơờớởỡợìíỉĩịäëïîöüûñçýỳỹỵỷ", | |
to = "aaaaaaaaaaaaaaaaaeeeeeeeeeeeduuuuuuuuuuuoooooooooooooooooiiiiiaeiiouuncyyyyy"; | |
for (var i=0, l=from.length ; i < l ; i++) { | |
str = str.replace(RegExp(from[i], "gi"), to[i]); | |
} | |
str = str.toLowerCase() | |
.trim() |
This file contains 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
.ribbon-container{ | |
width: 300px; | |
height: 300px; | |
background: #FFF; | |
} | |
.ribbon-container .ribbon{ | |
position:relative; | |
color:#fff; |