Skip to content

Instantly share code, notes, and snippets.

View nukturnal's full-sized avatar

Alfred Rowe nukturnal

View GitHub Profile
@nukturnal
nukturnal / audio_length.rb
Created January 18, 2010 22:54
Extracting audio length with Rails and ffmpeg
def self.get_audio_length(filepath)
pipe = "ffmpeg -i "+ filepath.to_s+" 2>&1 | grep 'Duration' | cut -d ' ' -f 4 | sed s/,//"
command = `#{pipe}`
if command =~ /([\d][\d]):([\d][\d]):([\d][\d]).([\d]+)/
#convert the result to only secs
duration = ($2.to_i * 60) + $3.to_i
end
#return and array containing the seconds and the human readable time length, ["6453","03:54"]
return "#{duration.to_s},#{$2}:#{$3}".split(",")
end
@nukturnal
nukturnal / simple_deploy.rb
Created September 18, 2012 03:44
Simple script to help with Rails deployment tasks. Requires "Rye Gem"
require 'rubygems'
require 'rye'
HOST = "yourserver"
USER = "username"
PASS = "password"
app_path = "/path/to/rails_app_root"
production_env = "RAILS_ENV=production"
@nukturnal
nukturnal / api_conf.php
Last active October 12, 2015 12:17
MPower PHP API Keys Configuration
<?php
MPower_Setup::setMasterKey("dd6f2c90-f075-012f-5b69-00155d866600");
MPower_Setup::setPublicKey("test_public_oDLVlm1eNyh0IsetdhdJvcl0ygA");
MPower_Setup::setPrivateKey("test_private_zzF3ywvX9DE-OSDNhUqKoaTI4wc");
MPower_Setup::setMode("test");
MPower_Setup::setToken("ca03737cf942cf644f36");
@nukturnal
nukturnal / store_conf.php
Last active October 12, 2015 12:17
MPower PHP Checkout Store Configuration
<?php
//Setup your Store information
MPower_Checkout_Store::setName("My Awesome Online Store");
MPower_Checkout_Store::setTagline("My awesome store's awesome tagline");
MPower_Checkout_Store::setPhoneNumber("0302507099");
MPower_Checkout_Store::setPostalAddress("Post office Box AN 10604");
@nukturnal
nukturnal / library.php
Created November 6, 2012 18:29
MPower PHP Library Setup
require('mpower/mpower.php');
@nukturnal
nukturnal / building_checkout_invoice.php
Last active October 12, 2015 12:28
MPower PHP Checkout Invoice setup
<?php
/* Adding items to your invoice is very basic, the parameters expected are
name_of_item, quantity, unit_price, total_price and optional item
description. */
$invoice->addItem("13' Apple Retina 500 HDD",1,10.99,10.99);
$invoice->addItem("Case Logic laptop Bag",2,100.50,201,"Optional description");
$invoice->addItem("Philips electric shaver",2,50.50,101.00);
/* You can optionally set a general invoice description text which can
be used in cases where your invoice does not need an items list or in cases
@nukturnal
nukturnal / total_amount.php
Last active October 12, 2015 12:37
MPower PHP Checkout Total Amount Set
<?php
$invoice->setTotalAmount(1200.99);
@nukturnal
nukturnal / add_tax.php
Last active October 12, 2015 12:38
MPower PHP Checkout Invoice Adding Tax
<?php
// The parameters for setting add tax are title_of_the_tax, tax_amount
$invoice->addTax('VAT (15%)',50);
$invoice->addTax('NHIL (5%)',50);
@nukturnal
nukturnal / cancel_url.php
Last active October 12, 2015 12:38
MPower PHP Checkout Invoice Cancel URL
<?php
// Globally setting cancel URL, the piece of code below
// should be included with the checkout shop setup code
MPower_Checkout_Store::setCancelUrl("http://www.myawesomeshop.com/");
// Setting the cancel URL on an invoice instance.
// This will overwrite any global settings for cancel URL
$invoice->setCancelUrl("http://www.myawesomeshop.com/");
@nukturnal
nukturnal / create_redirect_checkout.php
Last active October 12, 2015 12:47
MPower PHP Library Checkout Invoice Creation & Redirection
<?php
// The code below depicts how to create the checkout invoice on our servers
// and redirect to the checkout page.
if($invoice->create()) {
header("Location: ".$invoice->getInvoiceUrl());
}else{
echo $invoice->response_text;
}