Skip to content

Instantly share code, notes, and snippets.

View andrius's full-sized avatar

Andrius Kairiukstis andrius

View GitHub Profile
# Start Adhearsion in JRuby, while building a pidfile as soon as possible.
def ahnctl_start
shell_command = "#{exec_ahn_async} && #{wait} && #{save_pid}"
%x{shell_command}
end
private
# Run start in the background, since it is not daemonized.
echo 'export PATH=$HOME/local/bin:$PATH' >> ~/.bashrc
. ~/.bashrc
mkdir ~/local
mkdir ~/node-latest-install
cd ~/node-latest-install
curl http://nodejs.org/dist/node-latest.tar.gz | tar xz --strip-components=1
./configure --prefix=~/local
make install # ok, fine, this step probably takes more than 30 seconds...
curl https://npmjs.org/install.sh | sh
@andrius
andrius / mongodb_keys.rb
Last active December 29, 2015 17:49
Fixes 'not Ok for value' mongo DB error, when key contains '.' (DOT) character
def mongodb_keys(from,to,data)
if data.kind_of? Hash
result = {}
data.each_pair do |k,v|
result[k.to_s.gsub(from, to)] = mongodb_keys(from, to, v)
end
return result
elsif data.kind_of? Array
result = []
data.each do |v|
@andrius
andrius / rails.rb
Created November 27, 2013 16:15 — forked from simi/rails.rb
#!/usr/bin/env ruby
# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
require 'rubygems'
require 'rails/commands/server'
require 'rack'
require 'webrick'
require 'webrick/https'
module Rails
@andrius
andrius / ahn
Created August 20, 2013 20:34 — forked from ik5/ahn
#!/bin/sh
### BEGIN INIT INFO
# Provides: ahn
# Required-Start: ahn daemon
# Required-Stop: ahn daemon
# chkconfig: 2345 91 60
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Adhearsion daemon
@andrius
andrius / tts.sh
Last active June 8, 2022 17:27
Quick and dirty IVR sounds for your Asterisk PBX
#!/bin/bash
#title : tts.sh
#description : This script will convert text to speech using Google translate API
# and then to Asterisk formats (wav, sln, gsm)
#
#author : Andrius Kairiukstis <k@andrius.mobi>
#date : 26 July 2013
#version : 0.1
#usage : bash tts.sh FILENAME VOICE PHRASE
@andrius
andrius / campaign-next-number.rb
Created April 16, 2013 20:55
Any way to optimize? To ensure that its working on MySQL, SQLITE, Postgre SQL?
# Find next number to send call
def next_number
# first parse CDRs
Cdr.parse
# find number
sql_request = %{campaign_id = ? and
call_state = ? and
number_of_retries < ? and
(UNIX_TIMESTAMP(NOW()) - UNIX_TIMESTAMP(updated_at)) <= ?
@andrius
andrius / download-and-install.sh
Created March 14, 2013 23:16
Script to download and install Asterisk PBX, Ruby and Adhearsion AGI on debian-based system
#!/bin/bash
# function to generate random password, on input requires an argument - lenght of password
genpasswd() {
local l=$1
[ "$l" == "" ] && l=20
tr -dc A-Za-z0-9_ < /dev/urandom | head -c ${l} | xargs
}
# MySQL default root password
desc "Loads initial data (use once after migration)"
task "db:initialize" do
require './lib/initialize'
require 'fileutils'
# Print out DB log
ActiveRecord::Base.logger = Logger.new(STDOUT)
ActiveRecord::Base.logger.level = Logger::DEBUG
YAML::load_file("#{APP_ROOT}/config/pbxes.yml").each_pair do |name,params|
#!/usr/bin/env ruby
require 'monitor'
require 'pp'
require 'timeout'
require 'time'
require 'pp'
require 'rubygems'
require 'AGIServer'