Skip to content

Instantly share code, notes, and snippets.

Alexey Melnichuk moteus

View GitHub Profile
@moteus
moteus / multi_request.lua
Last active Apr 13, 2018
Run multiple curl requests from coroutines simultaneously
View multi_request.lua
local cURL = require "cURL.safe"
local json = require "cjson.safe"
-------------------------------------------------------------------
local MultiRequests = {} do
MultiRequests.__index = MultiRequests
function MultiRequests.new(...)
local self = setmetatable({}, MultiRequests)
return self:__init(...)
@moteus
moteus / registry.lua
Created Oct 19, 2017
Implementation registry in lua
View registry.lua
local Registry = {} do
Registry.__index = Registry
function Registry:new()
return setmetatable({_r = {0}}, {__index = self})
end
function Registry:ref(value)
local registry = self._r
@moteus
moteus / att_xfer_mon.lua
Last active Aug 10, 2017
Monitor transfer channels on FS and put info to memcache to be able do intercep
View att_xfer_mon.lua
-- This service can be run as standalone application
-- or from FreeSWITCH using `luarun att_xfer_mon.lua`
--------------------------------------------------------
local EventService = require "uv_event_service"
local Memcached = require "lluv.memcached"
local service_name = 'att_xfer'
local service = EventService.new(service_name, { '127.0.0.1', '8021', 'ClueCon',
@moteus
moteus / sms_bcd2gsm.lua
Last active May 1, 2017
API command to fix ALPHANUMERIC source numbers received from mod_gsmopen
View sms_bcd2gsm.lua
-- API command to fix ALPHANUMERIC source numbers received from mod_gsmopen
-- Usage: <action application="set" data="from=${lua(sms_bcd2gsm.lua ${from})}" />
-- !! Do not forget that for resending uses not `from` header but `from_full`.
--
-- https://github.com/moteus/lua-tpdu
--
assert(stream, 'this is API command')
local tut = require "tpdu.utils"
View sms_forward.lua
--! @usage
-- forward incoming message to some extension
-- <action application="lua" data="sms_forward.lua '${from}' '100@my.domain.com'" />
local function escape(s)
s = string.gsub(s, '\\', '\\\\')
s = string.gsub(s, '|', '\\|')
return s
end
@moteus
moteus / call_forward_api.lua
Last active Apr 18, 2017
FusionPBX. Use Lua code to build CF dialplan from Web UI
View call_forward_api.lua
local Database = require "resources.functions.database"
local route_to_bridge = require "resources.functions.route_to_bridge"
local json = require "resources.functions.lunajson"
local function decode_value(v)
return (string.gsub(v, [[\u00(%x%x)]], {
['22'] = '"';
['27'] = "'";
['26'] = "&";
['3C'] = "<"; ['3c'] = "<";
@moteus
moteus / pgmoon.lluv.lua
Last active Jun 23, 2017
Wrapper class to use lluv socket class with pgmoon
View pgmoon.lluv.lua
-- socket = require "pgmoon.lluv".Socket.new()
local ut = require "lluv.utils"
local socket = require "lluv.luasocket"
local flatten = require("pgmoon.util").flatten
local function Super(class)
return function(self, m, ...)
if class.__base and class.__base[m] then
return class.__base[m](self, ...)
View gismeteo.lua
local curl = require "cURL"
local lom = require "lxp.lom"
local GISMETEO_CODES = {
['7495'] = '27612_1';
['7496'] = '27612_1';
['7499'] = '27612_1';
}
local gismeteo_base_url = "http://informer.gismeteo.ru/xml/"
@moteus
moteus / native.lua
Last active Dec 14, 2016
Database class to works with parameters
View native.lua
--
-- Native backend to FusionPBX database class
--
local log = require "resources.functions.log".database
assert(freeswitch, "Require FreeSWITCH environment")
local param_pattern = "%f[%a%d:][:]([%a][%a%d_]*)"
@moteus
moteus / freeswitch.i
Created Nov 29, 2016
Dbh query with params for FS
View freeswitch.i
%module freeswitch
%{
#include "freeswitch_lua.h"
%}
%typemap(in, checkfn = "lua_isfunction") SWIGLUA_FN {
$1.L = L;
$1.idx = $input;
}
You can’t perform that action at this time.