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
%% Prints source code of a function. | |
%% | |
%% Requires debug_info | |
%% Will not work for modules mocked by meck | |
%% | |
%% > io:format("~s~n", [rf:print_function(dict, new, 0)]). | |
%% new() -> | |
%% Empty = mk_seg(16), | |
%% #dict{empty = Empty, segs = {Empty}}. |
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
is_exported(M, F, A) -> | |
%% make a cheap test first to avoid unnecessary calls to code server | |
case erlang:module_loaded(M) of | |
false -> code:ensure_loaded(M); | |
true -> ok | |
end, | |
erlang:function_exported(M, F, A). |
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
-export([uptime/0, uptime/1, uptime_string/0]). | |
%% @doc uptime in native time units | |
uptime() -> | |
erlang:monotonic_time() - erlang:system_info(start_time). | |
%% @doc uptime in specified time units | |
uptime(Unit) -> | |
erlang:convert_time_unit(uptime(), native, Unit). |
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
% If we have some amount of PostgreSQL instances and want to transfer data between them, | |
% in case when model has 'timeatamp' fields, we should check that both instances configured with the | |
% same timezone | |
on_same_timezone(Connections) -> | |
Tests = | |
[%% Check using TimeZone connection parameter | |
{fun(Conn) -> | |
{ok, TZ} = pgsql:get_parameter(Conn, <<"TimeZone">>), | |
TZ |
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
#![feature(phase)] | |
#[phase(plugin, link)] extern crate log; | |
extern crate green; | |
extern crate rustuv; | |
use std::io; | |
use std::os; | |
use std::io::{Listener,Acceptor,TcpStream}; | |
#[start] |
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
%% Usage: | |
%% TemplatesDir = "templates", | |
%% TemplatesNames = ["index.dtl", "_layout.dtl"], % filelib:wildcard("*.dtl", TemplatesDir) | |
%% LocalesDir = "locales", | |
%% Domain = "my_project", % phrases will be written to "locales/my_project.pot" | |
%% Messages = extract_messages(TemplatesDir, TemplatesNames), | |
%% write_pot(Messages, LocalesDir, Domain). | |
-module(erlydtl_xgettext). |
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
# -*- coding: utf-8 -*- | |
''' | |
Created on 2014-04-05 | |
@author: Sergey Prokhorov <[email protected]> | |
''' | |
import re | |
import operator | |
import decimal |
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
%%% @author Sergey Prokhorov <[email protected]> | |
%%% @copyright (C) 2013, Sergey Prokhorov | |
%%% @doc | |
%%% Simple gettext .mo file format parser for Erlang. | |
%%% | |
%%% Produce [{KeyPlurals::[binary()], TransPlurals::[binary()]}] orddict as | |
%%% output. | |
%%% Eg, for .po file (converted to .mo) | |
%%% <pre> | |
%%% msgid "Download" |
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
% Send plaintext email using gen_smtp https://github.com/Vagabond/gen_smtp | |
% This function sends email directly to receiver's SMTP server and don't use MTA relays. | |
% | |
% Example plaintext email: | |
% Mail = mail_plain(<<"Bob <[email protected]>">>, <<"Alice <[email protected]>">>, <<"The mail subject">>, <<"The mail body">>), | |
% send_email(Mail). | |
% | |
% Example email with image attachment: | |
% ImgName = "image.jpg", | |
% {ok, ImgBin} = file:read_file(ImgName), |
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
decode_data(Data, UserAgent, Fuid01) -> | |
Key = iolist_to_binary([binary:part(UserAgent, 0, min(25, size(UserAgent))), | |
Fuid01, | |
<<"I keep watch over you ;)">>]), | |
decode_chars(Data, Key, 0). | |
decode_chars(<<>>, _, _) -> | |
<<>>; | |
decode_chars(<<Char:8, Rest/binary>>, Key, Idx) -> | |
KeyPos = Idx rem size(Key), |