Skip to content

Instantly share code, notes, and snippets.

View amasses's full-sized avatar

Matthew Lewis amasses

View GitHub Profile
@amasses
amasses / callbacks.rb
Created March 7, 2013 08:35
I'm considering this modification as occasionally we see Errno::ECONNRESET if there are communication issues between the rails app and ES. While the indexing failing isn't good, the AR operation failing is worse (to me). Using Thread.new without joining should mean that the exception isn't raised back to the caller, but I'm not sure if in certai…
module Tire
module Model
# Main module containing the infrastructure for automatic updating
# of the _ElasticSearch_ index on model instance create, update or delete.
#
# Include it in your model: `include Tire::Model::Callbacks`
#
# The model must respond to `after_save` and `after_destroy` callbacks
# (ActiveModel and ActiveRecord models do so, by default).
@amasses
amasses / delay_until_reasonable.rb
Last active December 14, 2015 05:29
A minor extension to Sidekiq's #delay_until to make delaying emails until a reasonable time easier...
module Sidekiq
module Extensions
module Klass
def delay_until_reasonable(options = {})
reasonable_time = case Time.now.hour
when 0..7
Time.now.change(hour: 8)
when 22..24
Date.tomorrow.to_time.change(hour: 8)
else
@amasses
amasses / Procfile
Created December 13, 2012 12:41 — forked from czottmann/Procfile
worker: QUEUE=* bundle exec rake environment resque:work
scheduler: bundle exec rake environment resque:scheduler
@amasses
amasses / payment.js
Created October 2, 2012 06:29
Node.js payment example
https = require('https');
var payload = {
amount: 1000,
card_holder: "Mark Smith",
card_number: "5123456789012346",
card_expiry: "05/2013",
cvv: "123",
customer_ip: "123.4.5.6",
reference: "NODE" + Math.random()
@amasses
amasses / direct_post_tokenize_card_example.html
Created September 25, 2012 04:27
Direct Post (tokenize) example form
<form action="https://gateway.sandbox.fatzebra.com.au/v1.0/credit_cards/direct/TEST" id="direct-form" method="POST" novalidate="novalidate">
<input id="verification" name="verification" type="hidden" value="a36d46f0ac1af213b304a95c5d0354ee">
<input id="return_path" name="return_path" type="hidden" value="http://yourwebsite.com/purchase/complete">
<div class="control-group">
<label class="control-label" for="card_holder">Card Holder</label>
<div class="controls">
<input class="required" id="card_holder" minlength="2" name="card_holder" type="text">
</div>
</div>
@amasses
amasses / direct_post_token_purchase.html
Created September 25, 2012 01:11
Direct Post (token purchase) example form
<form action="https://gateway.sandbox.fatzebra.com.au/v1.0/purchases/direct/TEST" id="direct-form" method="POST" novalidate="novalidate">
<input id="reference" name="reference" type="hidden" value="INV-90386">
<input id="currency" name="currency" type="hidden" value="AUD">
<input id="verification" name="verification" type="hidden" value="a36d46f0ac1af213b304a95c5d0354ee">
<input id="amount" name="amount" type="hidden" value="100000">
<input id="return_path" name="return_path" type="hidden" value="http://yourwebsite.com/purchase/complete">
<p>Your Credit Card (5123XXXXXXXX2346) will be charged the amount of $1000.00. Please enter your card security code to confirm.</p>
<input type="hidden" name="card_token" value="xj8lk08a">
<div class="control-group">
@amasses
amasses / direct_post.html
Created September 25, 2012 01:08
Direct Post (purchase) example form
<form action="https://gateway.sandbox.fatzebra.com.au/v1.0/purchases/direct/TEST" id="direct-form" method="POST" novalidate="novalidate">
<input id="reference" name="reference" type="hidden" value="INV-90386">
<input id="currency" name="currency" type="hidden" value="AUD">
<input id="verification" name="verification" type="hidden" value="a36d46f0ac1af213b304a95c5d0354ee">
<input id="amount" name="amount" type="hidden" value="100000">
<input id="return_path" name="return_path" type="hidden" value="http://yourwebsite.com/purchase/complete">
<div class="control-group">
<label class="control-label" for="card_holder">Card Holder</label>
<div class="controls">
@amasses
amasses / fatzebra-example.cs
Created August 15, 2012 08:19
Fat Zebra.NET Library Example
// ensure you have added reference to the FatZebra DLL
FatZebra.Gateway.Username = "TEST";
FatZebra.Gateway.Token = "TEST";
FatZebra.Gateway.TestMode = true;
FatZebra.Gateway.SandboxMode = true;
var response = FatZebra.Purchase.Create(12000, "Mark Smith", "5123456789012346", DateTime.new(2013, 5, 30), "123", "INV-123009", "203.123.99.8");
if (response.Successful && response.Result.Successful)
@amasses
amasses / fatzebra-ruby.rb
Created August 15, 2012 08:17
Ruby Library Example
# Gemfile
gem "fat_zebra"
# In your code
require 'fat_zebra'
gw = FatZebra::Gateway.new("TEST", "TEST")
card = {
:number => "5123456789012346",
:expiry => "05/2013",
:cvv => "123",
@amasses
amasses / create-token.php
Created July 26, 2012 00:17
PHP token payments example
<?php
include_once("FatZebra.class.php");
define("FATZEBRA_USERNAME", "TEST");
define("FATZEBRA_TOKEN", "TEST");
define("FATZEBRA_GATEWAY", "gateway.sandbox.fatzebra.com.au"); // Live: gateway.fatzebra.com.au
define("FATZEBRA_TEST_MODE", true);
$gateway = new FatZebra\Gateway(FATZEBRA_USERNAME, FATZEBRA_TOKEN, FATZEBRA_TEST_MODE, FATZEBRA_GATEWAY); // The last option can be omitted to use the live gateway