Skip to content

Instantly share code, notes, and snippets.

View jicksta's full-sized avatar

Jay Phillips jicksta

View GitHub Profile
@jicksta
jicksta / gist:1001736
Created June 1, 2011 03:19
Jasmine shared behavior for asserting that a certain event on an element exposed as a Backbone view property properly executes the expected view instance method
function assertViewAction(viewClass, eventCallbackName, elementAccessorName, eventName, viewReference) {
it("should run the " + eventCallbackName + " action when the " + elementAccessorName + " gets a " + eventName + " event (assertViewAction)", function() {
var isPrototypal = eventCallbackName in viewClass.prototype;
if (isPrototypal) {
spyOn(viewClass.prototype, eventCallbackName);
}
var view = viewReference();
if (!isPrototypal) {
spyOn(view, eventCallbackName);
}
@jicksta
jicksta / gist:999529
Created May 30, 2011 21:51
Demonstrates a flaw in the late-binding nature of Javascript functions when doing Backbone-style class definitions. (Can execute this file with node or in a browser)
var Base = {
extend: function(proto) {
function f() {
if (this.init) this.init.apply(this, arguments);
};
f.prototype = proto;
return f;
}
};
@jicksta
jicksta / gist:984801
Created May 21, 2011 19:11
Use Underscore functions on any object
// Adding functions to the prototypes of Javascript "standard library" classes should
// never be done in code that will be released as a framework for others to use. You
// should only do it for the framework you build up on a web app that you have total
// control over.
var _ = require("underscore");
function UnderscorePrototypeImporter(proto, functions) {
_.each(functions, function(fnName) {
proto[fnName] = function(/* Any number of args */) {
class BlackHole
instance_methods.each { |m| undef_method m unless m =~ /^__/ }
def method_missing(*a) self end
end
BlackHole.new.doesnt.care("much").about(:anything, :you, :do).okay?
require 'pp'
# Storing all variables in a Hash so they can be printed in
# a way that shows everything related to the calculation.
x = {}
x[:task_count] = 1_000
x[:$task] = 0.01
x[:task_redundancy] = 2 # How many different users must do task
#----------
#Yahoo weather app using YQL/JSON
#----------
require 'open-uri'
require 'json'
answer
say 'Welcome to the Ruby Yahoo weather reader'
options = { :choices => "[5 DIGITS]",
#!/usr/bin/env ruby
require 'rubygems'
require 'adhearsion'
require 'adhearsion/voip/asterisk/manager_interface'
class MyManagerInterface < Adhearsion::VoIP::Asterisk::Manager::ManagerInterface
def event_message_received(event)
puts "Got an event! #{event.inspect}"
end
@jicksta
jicksta / gist:66109
Created February 18, 2009 00:43
Handling events when using Adhearsion's ManagerInterface class outside of Adhearsion
class MyManagerInterface < Adhearsion::VoIP::Asterisk::Manager::ManagerInterface
def event_message_received(event)
if event.name.downcase == "newstate"
puts "Got a newstate event! #{event.inspect}"
end
end
end
MyManagerInterface.connect ......
xenu /opt/sandbox-infrastructure/inbound_agi_tunnel % git pull
remote: Counting objects: 72, done.
remote: Compressing objects: 100% (62/62), done.
remote: Total 65 (delta 18), reused 0 (delta 0)
Unpacking objects: 100% (65/65), done.
From git@github.com:jicksta/sandbox-infrastructure
92a1e80..a206ec2 master -> origin/master
Updating 92a1e80..a206ec2
Fast forward
.gitignore | 3 +
xenu /home/hubbard % cat .bash_history
ls
vim /etc/motd
sudo vim /etc/motd
exit
quit
adduser jicksta
passwd jicksta
adduser
sudo adduser