Skip to content

Instantly share code, notes, and snippets.

@libryder
libryder / .autotest
Created April 12, 2012 16:06
Autotest fix for infinite loop on failed test
# Throw an exception when any of the following files/directories change to prevent autotest from running
Autotest.add_hook :initialize do |at|
%w{.svn .hg .git vendor rerun.txti db log tmp .DS_store Gemfile.lock}.each {|exception| at.add_exception(exception)}
end
class Item
attr_accessor :description, :completed
def initialize desc
@description = desc
@completed = false
end
end
@libryder
libryder / local_calling_guide.rb
Created March 14, 2012 21:13
Example using SimpleXml to parse API query to LocalCallingGuide.com
# lib/local_calling_guide.rb
# This file should be autoloaded when Rails starts
require 'rest_client'
require 'xmlsimple'
class LocalCallingGuide
def initialize
@url = "http://www.localcallingguide.com/xmllocalprefix.php"
nested_attributes = validate_hash[:criteria].merge({
'target_route' => {
'kind' => 'RouteByMessage',
'message_options_attributes' => {
'message' => 'blank',
'target_did' => ringto
}
}
}).with_indifferent_access
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"})
@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
@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 / 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 / .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 / 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