Skip to content

Instantly share code, notes, and snippets.

View mattheworiordan's full-sized avatar
💭
V. busy with Ably, building a great team 🚀

Matthew O'Riordan mattheworiordan

💭
V. busy with Ably, building a great team 🚀
View GitHub Profile
@mattheworiordan
mattheworiordan / value_for_undefined_key.js
Created July 29, 2011 14:44
Use case for valueForUndefinedKey error raised on simple close call to Window
var win = Titanium.UI.createWindow({
fullscreen: true,
backgroundColor: '#666',
url: 'value_for_undefined_key_subwindow.js'
});
win.addEventListener('ready', function() {
// win.close causes an error only if called immediately after window is created
win.close();
});
@mattheworiordan
mattheworiordan / swipe_detection_example.js
Created July 20, 2011 10:24
swipe detection example for Titanium
var movementHistory = {
pointAndTimeHistory: [],
set: function(point) {
// add this point into the point and time history for velocity calculations based on time & distance
this.pointAndTimeHistory.push({
time: new Date().getTime(),
x: point.x,
y: point.y
});
@mattheworiordan
mattheworiordan / rate_limit.js
Created July 15, 2011 14:49
Rate limiting function calls with JavaScript and Underscore.js
/* Extend the Underscore object with the following methods */
// Rate limit ensures a function is never called more than every [rate]ms
// Unlike underscore's _.throttle function, function calls are queued so that
// requests are never lost and simply deferred until some other time
//
// Parameters
// * func - function to rate limit
// * rate - minimum time to wait between function calls
// * async - if async is true, we won't wait (rate) for the function to complete before queueing the next request
@mattheworiordan
mattheworiordan / drag.js
Created July 9, 2011 18:12
Drag and drop example for Titanium
var circle = Titanium.UI.createView({
height:200,
width:200,
borderRadius:50,
backgroundColor:'#336699',
top:10,
left:50
});
currentWindow.add(circle);
@mattheworiordan
mattheworiordan / gist:1037984
Created June 21, 2011 14:35
Backbone patch to defer update method requests when new create requests are not complete on a model
(function() {
Backbone.Model.prototype._save = Backbone.Model.prototype.save;
Backbone.Model.prototype.save = function(attrs, options) {
var that = this;
if (!options) { options = {}; }
if (this.savingNewRecord) {
// store or replace last PUT request with the latest version, we can safely replace old PUT requests with new ones
// but if there are callbacks from a previous PUT request, we need to make sure they are all called as well
_(['success','error']).each(function(event) {
// convert all callbacks to a single array of callbacks)
module("Calculator");
test('calculator can perform basic operations', 2, function() {
var calc = new Calculator();
equals (calc.sum(5,10), 15, 'Simple addition');
equals (calc.multiple(5,5), 25, 'Simple multiplication');
});
test('AJAX addition operation', 2, function() {
stop(5000); // wait for up to 5 seconds
@mattheworiordan
mattheworiordan / Gemfile
Created April 16, 2011 17:05
gemfile for RSpec
gem 'spork', '~> 0.9.0.rc'
@javascript
Scenario: confiming when saving inactive
Given I expect to click "OK" on a confirmation box saying "Are you sure?"
When I press "Save"
Then the confirmation box should have been displayed
And I should see "TV" in the "Campaign Keywords" section
Scenario: alert when form is not valid
Given I expect to click on an alert box saying "Please complete all fields in this form"
When I press "Save"
scenario "have ability to edit profile", :js => true do
@ability.should be_able_to(:edit, @profile)
end
require 'growl'
require 'open3'
ENV["WATCHR"] = "1"
$spec_cmd = "rspec --tty --drb --colour --format nested"
$cuke_cmd = "cucumber --color --drb --require features/step_definitions --require features/support"
$pass = File.join(File.expand_path(File.dirname(__FILE__)), '.watchr_images', 'pass.png')
$fail = File.join(File.expand_path(File.dirname(__FILE__)), '.watchr_images', 'fail.png')
$pending = File.join(File.expand_path(File.dirname(__FILE__)), '.watchr_images', 'pending.png')