Skip to content

Instantly share code, notes, and snippets.

View saranyan's full-sized avatar

Saranyan saranyan

View GitHub Profile

Keybase proof

I hereby claim:

  • I am saranyan on github.
  • I am saranyan (https://keybase.io/saranyan) on keybase.
  • I have a public key whose fingerprint is 51E0 7B3A 9317 6503 722C 2648 8D6B 045B ECCC C1B5

To claim this, I am signing this object:

@saranyan
saranyan / MPL_1.java
Created November 29, 2011 17:46
PayPal MPL Integration into an Art Store
//Full source code is available at https://github.com/saranyan/PayPal-Code-Examples
//---------------------------------------------------------------------
//Step 1 - Initialize.
//Do this before anything else.
public void initLibrary() {
PayPal pp = PayPal.getInstance();
if (pp == null) {
// This is the main initialization call that takes in your Context,
@saranyan
saranyan / catalog.avdl
Created December 7, 2011 22:20
X.commerce catalog capability
@namespace("com.x.service.catalog")
/**
* Protocol for the Catalog Service
* ================================
*/
protocol CatalogService {
//-----------------------------------------------------------------------------------------------------
// Request & Response: Product Types
@saranyan
saranyan / avdl_to_avpr
Created December 7, 2011 22:53
avro idl command
java -jar avro-tools-1.5.4.jar idl catalog.avdl /tmp/catalog.avpr
@saranyan
saranyan / catalog.avpr
Created December 7, 2011 23:00
Catalog avpr file
{
"protocol" : "CatalogService",
"namespace" : "com.x.service.catalog",
"types" : [ {
"type" : "record",
"name" : "GetProductTypesMessage",
"fields" : [ {
"name" : "locale",
"type" : [ "null", "string" ]
} ],
@saranyan
saranyan / avro_parse.rb
Created December 7, 2011 23:07
Ruby implementation to Parse Avro schema
CONTRACT_PROTOCOL_JSON = <<-EOS
{
"protocol" : "CatalogService",
"namespace" : "com.x.service.catalog",
"types" : [ {
"type" : "record",
"name" : "GetProductTypesMessage",
"fields" : [ {
"name" : "locale",
"type" : [ "null", "string" ]
@saranyan
saranyan / active_merchant.rb
Created December 20, 2011 16:38
PayPal IPN using Active merchant
if Rails.env.production?
PAYPAL_ACCOUNT = 'production@gmail.com'
else
PAYPAL_ACCOUNT = 'development@gmail.com'
ActiveMerchant::Billing::Base.mode = :test
end
@saranyan
saranyan / ipn_example.rb
Created December 27, 2011 18:38
IPN without active merchant
#from http://www.ruby-forum.com/topic/163331#817338
#this code will also work if you are not using active merchant.
if request.post?
#new
@params = params
@params[:cmd] = "_notify-validate"
@params.delete(:action)
@params.delete(:controller)
url = URI.parse("https://www.paypal.com/cgi-bin/webscr")
@saranyan
saranyan / main.c
Created January 31, 2012 14:08
Testing Ruby FFI - Calling from C and Ruby
#include <stdio.h>
#include "mylibrary.h"
int main(){
char x[10];
double d = 10.0;
double *dp = &d;
double dd[3];
printf("tf0 - %lf\n",calculate_something(1,2.33));
@saranyan
saranyan / mylibrary.c
Created January 31, 2012 13:55
Testing Ruby FFI - C side
#include "mylibrary.h"
#include <stdio.h>
double calculate_something(int a, float b)
{
return a+b;
}
const char* test_function_1(const char *w)
{