Skip to content

Instantly share code, notes, and snippets.

@mbeale
mbeale / gist:4242532
Created December 8, 2012 23:38
Dynamic JSON sample golang #2
//Document Container
type JSONContainer struct {
data []interface{}
}
//Return all objects
func (j *JSONContainer) All() (objects []JSONObject) {
for _, v := range j.data {
newJSONObject := JSONObject{data: v}
objects = append(objects, newJSONObject)
@mbeale
mbeale / gist:4242562
Created December 8, 2012 23:46
Dynamic JSON sample golang #3
val, _ := v.Get("payload.deeper_nesting.return_value")
@mbeale
mbeale / gist:4247971
Created December 10, 2012 02:01
Dynamic JSON sample golang #4
type JSONContainer struct {
data []interface{}
}
func (j *JSONContainer) All() (objects []JSONObject) {
for _, v := range j.data {
objects = append(objects, JSONObject{data: v})
}
return
}
@mbeale
mbeale / gist:4247991
Created December 10, 2012 02:12
Dynamic JSON sample golang #5
func main(){
dyn, err := MakeJSONContainer(rawData)
if err != nil {
fmt.Println("error:", err)
} else {
for _, v := range dyn.All() {
if val ,err := v.Get("payload.deeper_nesting.return_value");err == nil {
println(val)
} else {
fmt.Println("error:", err)
@mbeale
mbeale / gist:4262206
Created December 11, 2012 21:18
Sample code change
Turns this:
accounts = Account.all()
while accounts:
for account in accounts:
print 'Account: %s' % account
try:
accounts = accounts.next_page()
except PageError:
accounts = ()
£ == £
@mbeale
mbeale / gist:4741709
Last active December 12, 2015 08:08
Complete example for PHP Recurly.js BuildSubscriptionForm
<?php
require_once('recurlyphp/lib/recurly.php');
// Required for the API
Recurly_Client::$subdomain = 'yoursubdomain'
Recurly_Client::$apiKey = 'apikey';
Recurly_js::$privateKey = 'privatekey';
$signature = Recurly_js::sign(array('account'=>array('account_code'=>'aaa1234588'),'subscription' => array(
'plan_code' => 'plan_trial',
@mbeale
mbeale / gist:4742795
Last active December 12, 2015 08:18
Onetime transaction with Recurly.js and PHP
<?php
require_once('recurlyphp/lib/recurly.php');
// Required for the API
//greenlantern
Recurly_Client::$apiKey = 'yourapikey';
Recurly_js::$privateKey = 'yourprivatekey';
$signature = Recurly_js::sign(array('account'=>array('account_code'=>'1'),'transaction' => array('description' => "test trans \n for you",'amount_in_cents'=>'999')));
?>
@mbeale
mbeale / gist:5187700
Created March 18, 2013 14:52
Recurly.js submit coupon automatically
Recurly.buildSubscriptionForm({
/* other options */
subscription: {
couponCode: 'testplan'
},
distinguishContactFromBillingInfo: true,
afterInject: function(){
$('.submit').text('Join Playa');
$('div.check').click();
},
@mbeale
mbeale / gist:5207507
Created March 20, 2013 19:08
Alter expiration fields Recurly.js
Recurly.buildSubscriptionForm({
/* other options */
afterInject: function(){
$('.month select').val(2); //month
$('.year select').val(2016); //year
},
});