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 / restart.sh
Created August 19, 2017 13:23
Heroku scheduled restarts
#!/bin/sh
# Set up the Heroku scheduler to run this command every hour. See example setup at https://goo.gl/nMCSH3
#
# Requires env vars to be set in Heroku with `heroku config:set`:
# - HEROKU_APP_NAME: this is just the app name in Heroku, i.e. `heroku apps` will list all apps you have access to
# - HEROKU_CLI_USER: Once Heroku CLI is authenticated (https://goo.gl/Qypr4x), check `cat .netrc` (or `_netrc` on Windows),
# look for `login` under `machine api.heroku.com`
# - HEROKU_CLI_TOKEN: As above, but use the `password` field
#
@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 / application.rb
Created March 28, 2014 09:05
CloudFlare IP Middleware for Rails to ensure HTTP_CF_CONNECTING_IP is used and the clients IP is correct within Rails
module RailsAppName
class Application < Rails::Application
# .... your settings
require "#{Rails.root}/lib/cloud_flare_middleware"
config.middleware.insert_before(0, Rack::CloudFlareMiddleware)
# ... your settings
end
end
@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)
@mattheworiordan
mattheworiordan / cli.rb
Created January 9, 2015 12:21
Thor with subcommands that work correctly with help
#!/usr/bin/env ruby
require 'thor'
class SubCommandBase < Thor
def self.banner(command, namespace = nil, subcommand = false)
"#{basename} #{subcommand_prefix} #{command.usage}"
end
def self.subcommand_prefix
@mattheworiordan
mattheworiordan / Gemfile
Created September 7, 2011 12:06
Test PDF within Cucumber and Capybara
# normal Gem dependancy declarations
# ...
group :test, :cucumber do
gem 'pdf-reader'
end
@mattheworiordan
mattheworiordan / publish-with-idempotency-for-retries.js
Created April 18, 2019 11:35
Ably Idempotency for automatic retries by our SDKs
var rest = new Ably.Rest(key: ablyApiKey, idempotentRestPublishing: true);
var channel = rest.channels.get('example-channel');
channel.publish([{ data: 'payload' }]);
@mattheworiordan
mattheworiordan / publish-with-client-supplied-id.js
Last active April 18, 2019 11:35
Ably Idempotency with client supplied message ID
var rest = new Ably.Rest(ablyApiKey);
var channel = rest.channels.get('example-channel');
channel.publish([{ data: 'payload', id: 'unique123' }]);
@mattheworiordan
mattheworiordan / offer.md
Last active November 26, 2018 14:47
Recommend a distributed system engineer we employ and earn yourself $3,000

Unfortunately we're finding it really hard to find good distributed systems engineers at Ably, a distributed realtime data delivery platform.

We know a lot of you out there probably know great people who love solving truly hard distributed problems with a distributed team of superb engineers.

If you know anyone who fits the bill, wants to work remotely and is based in Europe (or wants to work on-site in London), we'll give you $3,000 simply for the referral if we end up employing them.

Follow these steps to earn $3,000 for one minute of your time:

  1. Contact the people you think are suitable for our Distributed Systems Engineer role and tell them to apply on that page
  2. Email us at engineer-referral@ably.io with the name or