Skip to content

Instantly share code, notes, and snippets.

@avimar
avimar / playerror.lua
Created January 23, 2013 07:14
Avi's Freeswitch play error lua script
calling_card = session:getVariable("calling_card_ivr")
cause = session:getVariable("originate_disposition")
cause2=session:getVariable("bridge_hangup_cause")
if cause == nil then cause="none" end
session:execute("log", "DEBUG Hangup cause: "..cause);
if cause2 == nil then cause2="none" end
session:execute("log", "DEBUG bridge hangup cause: "..cause2);
@avimar
avimar / pcap2wav
Last active March 1, 2023 22:32
Convert raw PCAP files into a .wav file
#!/bin/bash
#
# pcap2wav
# Original Author: Michael Collins <msc@freeswitch.org>
#Standard disclaimer: batteries not included, your mileage may vary...
# Updated by Avi Marcus <avi@bestfone.com>
#
# Accepts arg of pcap file w/only 2 RTP streams
# Creates a .<codec> file and a .wav file
# For codecs other than PCMA and PCMU the script calls fs_cli and does a little recording to create the wav file(s)
@avimar
avimar / gist:3092732
Created July 11, 2012 19:37
install node.js from source with salt
nodejs-deps:
pkg.installed:
- names:
- g++
- curl
- libssl-dev
- apache2-utils
require:
- pkg: git
@avimar
avimar / web_toast.js
Created February 10, 2021 15:49
Web Toasts
import Toastify from 'toastify-js'; //https://github.com/apvarun/toastify-js/blob/master/README.md
import "toastify-js/src/toastify.css";
//To use:
//import toast from '../web_toast.js';
//toast(message,class(optional), options)
//My default is that the toast stays open until dismissed and defaults to bootstrap's "bg-info" if no class is specified.
//NOTE: In an SPA, you'll need to clear any persistent toasts on page switch
//use import {closeAll as clearToasts} from './web_toast.js';
<script>
export let params={};
export let service=null;
export let id=null;
import Fa from 'svelte-fa'
import { faEdit, faPlus, faTrash } from '@fortawesome/free-solid-svg-icons';
import feathers from '../web_feathers.js';
const rest = feathers.service('logs');
@avimar
avimar / knex-functions.js
Created August 28, 2016 07:15
knex mysql update on duplicate and replace
function upsert(table, data, update){
if(!update) update=data;
var insert = knex(table).insert(data).toString();
var update = knex(table).update(update).toString().replace(/^update .* set /i, '');
return knex.raw(insert + ' on duplicate key update ' + update);
}
function replace(table, data){
var insert = knex(table).insert(data).toString().replace(/^INSERT/i, 'REPLACE');
return knex.raw(insert);
@avimar
avimar / isracard.js
Last active June 18, 2020 10:04 — forked from etodanik/isracard.js
Checks the validity of a given Isracard credit card number
/*License: MIT*/
function isracardCheck(num) {//algorithm explanation: https://web.archive.org/web/20140227235803/http://povolotski.me/2013/09/24/isracard-credit-card-number-validation-2/
if(typeof num !== 'number') num=''+num;
if(num.length < 8 || num.length > 9) return false;
var sum=0;
num.split('').forEach(function(val,key){
sum+=parseInt(val,10)*(num.length-key);
})
return sum % 11 == 0;
}
@avimar
avimar / index.js
Created February 15, 2019 08:03
FreeSWITCH de-register monitor
#! /usr/bin/node
var nodemailer = require("nodemailer");
var transport = nodemailer.createTransport("sendmail");
function fix_len(num, len){
if(len<=5) return ("00000" + num).slice(-len);
else {
var seed="0000000000";
while(seed.length<len) seed+=seed;
@avimar
avimar / 1.txt
Last active February 26, 2018 16:07
testing window.open prevention
Sample file.
This is free and unencumbered software released into the public domain.
Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.
In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit