View plug_cache.ex
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} ->
View bucket.ex
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
View paginator.ex
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{
View slug.js
function stringToSlug(str) {
// remove accents
var from = "àáãảạăằắẳẵặâầấẩẫậèéẻẽẹêềếểễệđùúủũụưừứửữựòóỏõọôồốổỗộơờớởỡợìíỉĩịäëïîöüûñç",
to = "aaaaaaaaaaaaaaaaaeeeeeeeeeeeduuuuuuuuuuuoooooooooooooooooiiiiiaeiiouunc";
for (var i=0, l=from.length ; i < l ; i++) {
str = str.replace(RegExp(from[i], "gi"), to[i]);
}
str = str.toLowerCase()
.trim()
View ribbon.css
.ribbon-container{
width: 300px;
height: 300px;
background: #FFF;
}
.ribbon-container .ribbon{
position:relative;
color:#fff;
View decorator don gian.py
__author__ = 'bluzky'
def name_decorator(f):
def wrapper(ten):
chuoi_moi = "Ten tui la %s" % ten
return f(chuoi_moi)
return wrapper
# su dung decorator
@name_decorator
View string_convert.cpp
wstring utf8_to_utf16(string utf8)
{
std::vector<unsigned long> unicode;
size_t i = 0;
while (i < utf8.size())
{
unsigned long uni;
size_t todo;
bool error = false;
unsigned char ch = utf8[i++];