Skip to content

Instantly share code, notes, and snippets.

@yazinsai
yazinsai / index-without-token.php
Last active August 29, 2015 14:12
Create and charge a customer using pure PHP (for Alexey)
<?php
# Step 1: Create a customer from the card details
require_once("vendor/autoload.php");
White::setApiKey("test_sec_k_886a1e89b2c0abce479bf"); // Secret key
$customer = White_Customer::create(array(
'name' => "John Doe",
'description' => "Amember customer",
'email' => "john.doe@example.com",
'card' => array(
@yazinsai
yazinsai / charge.cs
Last active August 20, 2016 04:00
Creating a charge using C# with RestSharp
// White doesn't provide a C# wrapper library (yet), but you can still easily
// create charges by sending requests directly to the API. Here's how.
using RestSharp;
var client = new RestClient();
client.BaseUrl = "https://api.start.payfort.com/";
client.Authenticator = new HttpBasicAuthenticator("your_secret_api_key_here", "");
var request = new RestRequest("charges", Method.POST); // send a POST request
request.AddParameter("currency", "AED");
@yazinsai
yazinsai / how-to-bill-a-token.php
Last active August 29, 2015 14:14
Bill a token -- John
# From https://whitepayments.com/docs/api/#create-a-new-charge
<?php
require_once('./lib/White.php');
White::setApiKey("test_sec_k_886a1e89b2c0abce479bf"); # Your secret API key
White_Charge::create(array(
"amount" => 1000, // 10.00
"currency" => "aed",
"card" => "tok_38951a48cd3859d2dcf62957e1c9", # The token from White.js
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
manager.responseSerializer = [AFJSONResponseSerializer serializer];
manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/json"];
NSDictionary *params = @{@"amount":@"1000",
@"currency":@"aed",
@"email":@"ahmed@example.com",@"card[name]":@"Abdullah Ahmed",
@"card[number]":@"4242424242424242",
@"card[exp_month]":@"11",
@"card[exp_year]":@"2016",
@"card[cvc]":@"123",
<?php
$token = $_POST['startToken']; // from Beautiful.js
require_once('./lib/Start.php');
Start::setApiKey("test_sec_k_e06df93760b388375e1f6");
Start_Customer::create(array(
"name" => "Abdullah Ahmed",
"email" => "abdullah@msn.com",
"card" => $token,
<?php
// Setup Start object
require_once('./lib/Start.php');
Start::setApiKey("test_sec_k_e06df93760b388375e1f6");
// Get the customer ID (usually from your Database)
$customer_id = "cus_abc123def456ghi789";
// Charge the customer (can be done many times, over a period of time)
Start_Charge::create(array(
# y = theta_1 * x + theta_0
# Not actually required in the gradient descent calculation; just used to verify
# the sanity of the results :)
def compute_error_for_line_given_points(theta_0, theta_1, points):
totalError = 0
for i in range(0, len(points)):
x = points[i, 0]
y = points[i, 1]
totalError += (y - (theta_1 * x + theta_0)) ** 2
return totalError / (2 * float(len(points)))
32.502345269453031 31.70700584656992
53.426804033275019 68.77759598163891
61.530358025636438 62.562382297945803
47.475639634786098 71.546632233567777
59.813207869512318 87.230925133687393
55.142188413943821 78.211518270799232
52.211796692214001 79.64197304980874
39.299566694317065 59.171489321869508
48.10504169176825 75.331242297063056
52.550014442733818 71.300879886850353
@yazinsai
yazinsai / ImportJSON.gs
Created April 26, 2016 13:38
Get data from any API straight into your Google Sheets, effortlessly!
/*====================================================================================================================================*
ImportJSON by Trevor Lohrbeer (@FastFedora)
====================================================================================================================================
Version: 1.2.1
Project Page: http://blog.fastfedora.com/projects/import-json
Copyright: (c) 2012-2013 by Trevor Lohrbeer
License: GNU General Public License, version 3 (GPL-3.0)
http://www.opensource.org/licenses/gpl-3.0.html
------------------------------------------------------------------------------------------------------------------------------------
A library for importing JSON feeds into Google spreadsheets. Functions include:
/*
Coded by Marjan Olesch
Sketch from Insctructables.com
Open source - do what you want with this code!
*/
#include <Servo.h>
int PIN_ESC = 9, value = 0;
Servo srvESC;