Skip to content

Instantly share code, notes, and snippets.

class CallFlow < ActiveRecord::Base
belongs_to :routable, :polymorphic => true
#validates_presence_of :dnis
#validates_uniqueness_of :dnis
def dialplan
puts self.routable.description.squeeze("\n").strip
end
def target_route=(params)
@libryder
libryder / application_controller.rb
Created February 19, 2012 23:34
Simple solution to enable transaction rollbacks
class ApplicationController < ActionController::Base
around_filter :check_dry_run
def check_dry_run
ActiveRecord::Base.transaction do
yield
raise ActiveRecord::Rollback, "dry_run specified; no changes made" if @dry_run
end
end
@libryder
libryder / .bashrc
Created February 15, 2012 17:41
Alternative to SCP - bash script
function push_file() {
file=$1
host=wherever.com
pass=secret
user=bau5
dir=dir_to_cdto
ftp -invp $host<<ENDOFUPLOAD
user $user $pass
cd $dir
@libryder
libryder / scheduling.rb
Created February 1, 2012 20:34
A sample scheduling solution for rufus-scheduler running in Apache
require 'server_mon'
require 'call_testing'
SCHEDULER = Rufus::Scheduler.start_new
TESTCALL = SCHEDULER.every '10m', :tags => 'testcall' do
CallTesting.test_call
end
CALLENGINE_MON = SCHEDULER.every '5m', :tags => 'callengine' do
class CallFlow < ActiveRecord::Base
belongs_to :routable, :polymorphic => true
def dialplan
puts self.routable.description.squeeze("\n").strip
end
def target_route=(params)
self.routable = params[:kind].constantize.new(params.reject {|k,v| k == "kind"})
end
@libryder
libryder / medium.rb
Created January 25, 2012 17:15
Convert wav -> mp3 and upload to S3
class Medium < ActiveRecord::Base
attr_accessible :title, :wav
has_attached_file :wav,
:styles => {
:mp3 => {
:params => "-encode --vbr-new -V7",
:format => "mp3" }
},
:default_style => :normal,
:processors => [:wav_mp3],
@libryder
libryder / app_swift-2.0.patch
Created January 25, 2012 16:30
app_swift patch to fix segfault bug
diff -ruN app_swift-2.0_ast-1.6.orig/app_swift.c app_swift-2.0_ast-1.6/app_swift.c
--- app_swift-2.0_ast-1.6.orig/app_swift.c 2010-06-16 08:35:30.000000000 +0930
+++ app_swift-2.0_ast-1.6/app_swift.c 2010-08-17 20:31:08.000000000 +0930
@@ -409,7 +409,8 @@
ASTOBJ_WRLOCK(ps);
ps->immediate_exit = 1;
ASTOBJ_UNLOCK(ps);
- } else if (f->frametype == AST_FRAME_DTMF && timeout > 0 && max_digits > 0) {
+ } else {
+ if (f->frametype == AST_FRAME_DTMF && timeout > 0 && max_digits > 0) {
@libryder
libryder / dialplan.rb
Created January 19, 2012 16:23
Attempt at adhearsion canadian georouting
#return a 6 digit DTMF entry from the caller
postcode = input 6, :speak => { :text => 'enter your postal code' }
postparts = postcode.split(//)
#simple map of possible alphabetical entries for a canadian post code
dtmf_map = { '2' => ['"A"','"B"','"C"'], '3' => ['"E"'], '4' => ['"G"','"H"'], '5' => ['"J"','"K"','"L"'], '6' => ['"M"','"N"'], '7' => ['"P"','"R"','"S"'], '8' => ['"T"','"V"'], '9' => ['"X"','"Y"'] }
#first, third, and fifth characters are always alphabetical
first_char = dtmf_map[postparts[0]].join(',')
@libryder
libryder / dialplan.rb
Created January 12, 2012 17:14
Outbound dialer example in Adhearsion
# Check pin number against user's attempt, wait for a number to dial, connect caller to callee and play disclaimer to callee
# The method of setting these variables has been simplified for clarity
pin = '1234'
caller_id = '1112223333'
play_prompt = true
tts = '...'
if play_prompt
tts = format_ssml("Please enter your pin number.")
@libryder
libryder / api_class.php
Created December 14, 2011 16:56
LogMyCalls API PHP Sample
<?php
/* LogMyCalls public API
*
* PHP Sample
* Author: David Ryder
* dryder@contactpoint.com
* http://github.com/libryder
*
* The LmcApi is a JSON wrapper using CURL to send and receive data