Skip to content

Instantly share code, notes, and snippets.

@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 / 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
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 / sln_0001.rb
Created February 20, 2012 08:49
ProjectEuler solutions
# http://projecteuler.net/problem=1
#
# If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.
#
# Find the sum of all the multiples of 3 or 5 below 1000.
sum = 0
(1..999).each do |n|
if n.modulo(5) == 0 || n.modulo(3) == 0
sum += n
@libryder
libryder / .bash_profile
Created February 20, 2012 16:55
Easily push and pull files between servers
file=$1
server=server.com
user=user
pass=pass
bucket=/uploads
dl_location=http://host.com
function push_file() {
ftp -invp "$server"<<ENDOFUPLOAD
user $user $pass
@libryder
libryder / api_class.rb
Created February 21, 2012 19:50
LogMyCalls API Ruby Sample
require 'json'
require 'rest_client'
# Requires: rest_client (gem install rest-client)
class LmcApi
def initialize
@url = 'https://api.logmycalls.com/services'
@auth = {
@libryder
libryder / curl_alternative.php
Created February 22, 2012 17:10
Method to post to a rest service without cURL
<?php
$data = array (
"limit" => 5,
"api_key" => 'YOUR_API_KEY',
"api_secret" => 'YOUR_API_SECRET',
);
$method = "getCallDetails";
$url = "https://api.logmycalls.com/services/$method";
$opts = array('http' =>
array(
@libryder
libryder / garbage.rb
Created February 29, 2012 04:14
Awesome refactoring
@parent_ou = OrganizationalUnit.where("api_key='#{@api_key}' and api_secret='#{@api_secret}' and master_node=1")
#get first descendents of ou then find all of their children recursively
children = @parent_ou.first.children
ou_children = (children + children.map(&:children)).flatten
#put the children ouid's in a new array
@ous = Array.new
ou_children.each do |child|
@ous.push child.id
class CallFlow < ActiveRecord::Base
establish_connection "callengine_#{Rails.env}"
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"})
nested_attributes = validate_hash[:criteria].merge({
'target_route' => {
'kind' => 'RouteByMessage',
'message_options_attributes' => {
'message' => 'blank',
'target_did' => ringto
}
}
}).with_indifferent_access