Skip to content

Instantly share code, notes, and snippets.

@libryder
libryder / restful_rpc.rb
Created August 31, 2011 16:27
Web component of restful_clicktocall
begin
require 'rack'
require 'json'
rescue LoadError
abort "ERROR: restful_rpc requires the 'rack' and 'json' gems"
end
# Don't you love regular expressions? Matches only 0-255 octets. Recognizes "*" as an octet wildcard.
VALID_IP_ADDRESS = /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|\*)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|\*)$/
@libryder
libryder / queues.conf
Created September 20, 2011 16:47
asterisk queue example
[4352754916]
strategy=ringall
timeout=15
retry=1
wrapuptime=0
maxlen=0
member=> SIP/elastix-trunk/525
member=> SIP/elastix-trunk/524
@libryder
libryder / call.js
Created September 21, 2011 14:22
clicktocall widtget
// Written by Jay Phillips
// The "viewer_element" arg should be a <div> with one <p> child that's hidden by default.
function AhnCall(viewer_element, source, destination) {
this.viewer = viewer_element;
this.text_holder = $(viewer_element.children()[0]);
this.source = source;
this.destination = destination;
@libryder
libryder / ssc.sh
Created September 21, 2011 21:58
Linux screenshot program
#!/bin/bash
#############################################################
# SSC - Linux screenshot script
#
# Take screenshot (window, selection, fullscreen), upload
# to ftp, imageshack, or none and copy URL/file location
# to clipboard
#
# Dependencies: scrot, xclip, zenity, imagemagick
@libryder
libryder / dialplan.rb
Created October 6, 2011 17:30
Basic setup requirements for enabling dynamic queues in adhearsion
# Example dialplan to handle asterisk queues
# outbound context for a local channel
outbound {
gconfig = GlobalConfiguration.first
trunk = gconfig.main_trunk
number = extension.to_s.scan(/\d/).join[-10,10]
dialstring = "SIP/#{trunk}/+1#{number}"
@libryder
libryder / Gemfile
Created October 16, 2011 00:52
Config files for integrating adhearsion and rails
source 'http://rubygems.org'
gem 'adhearsion', '>= 1.2.1'
gem 'ahn-restful-rpc'
gem 'rails', '3.1.1'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
@libryder
libryder / base_controller.rb
Created October 29, 2011 03:04
Typo (6.0.9) fix that allows for new migration version naming scheme
# app/controllers/admin/base_controller.rb
def look_for_needed_db_updates
if Migrator.offer_migration_when_available
redirect_to :controller => '/admin/settings', :action => 'update_database' if Migrator.migrations_available
end
end
@libryder
libryder / crash_asterisk.rb
Created November 8, 2011 18:44
Crash asterisk with adhearsion
#as soon as caller hangs up, asterisk goes down
cellphone_ivr {
key = input 1, :timeout => 5.seconds, :speak => {:text => "You appear to be calling from the #{@calling_area} area; Press 1 if correct. Press 2 to enter zipcode.", :interruptible => true}
if key == "1"
speak "One moment please."
+route_to_store
elsif key == "2"
+play_enter_zip_ivr
else
class OrganizationalUnit < ActiveRecord::Base
has_many :children, :class_name => "OrganizationalUnit", :foreign_key => :parent_id
def children?
children.present?
end
end
@libryder
libryder / rename_table_column.rb
Created November 12, 2011 19:53
Migration example to rename column
# It's recommended to change the class and filename to be a little more descriptive for your environment
class RenameTableColumn < ActiveRecord::Migration
def up
rename_column :table_name, :producthistory_id, :product_history_id
end
def down
rename_column :table_name, :product_history_id, :producthistory_id
end