Skip to content

Instantly share code, notes, and snippets.

View tiagomatos's full-sized avatar

Tiago Matos tiagomatos

View GitHub Profile
@tiagomatos
tiagomatos / client_create_invoice_with_tax
Created October 26, 2012 23:33
InvoceXpress Client Create Invoce does not accept item tax.
require 'uri'
require 'net/https'
require 'ostruct'
require 'rubygems'
require 'yaml'
invoicexpressyml ||= YAML.load_file("config/invoicexpress.yml")
invoicexpresscfg = invoicexpressyml["development"]
host = [invoicexpresscfg["screen_name"], invoicexpresscfg["host"]].join(".")
api_key = invoicexpresscfg["api_key"]
countries:
PT: Portugal
IE: Ireland
GB: UK
CA: Canada
US: United States
AF: Afghanistan
AL: Albania
DZ: Algeria
AS: American Samoa
@tiagomatos
tiagomatos / gist:11379118
Created April 28, 2014 17:49
Log Jumpseller notifications in PHP
<?
$body = file_get_contents('php://input');
#$data = json_decode($body, true); #decode JSON string.
file_put_contents("jumpseller_posts.txt", date("Y-m-d H:i:s")."\n".$body, FILE_APPEND);
?>
@tiagomatos
tiagomatos / memmory.rb
Created March 18, 2016 17:41
method to output Linux memory use by server thread in an array
def self.memmory(app_name, url)
pid, size = `ps ax -o pid,rss | grep -E "^[[:space:]]*#{$PROCESS_ID}"`.strip.split.map(&:to_i)
size_in_mb = size / 1024.0
{ pid: pid, app: app_name, size: size_in_mb, url: url, server_time: Time.now }
end
Jumpseller.addProductToCart(336248, 1, {"Sexo":379610, "Modelo":379612, "Color": 379615, "Cuello": 379621, "Manga": 379623})
@tiagomatos
tiagomatos / gist:ce23ca38ffa0e666b8364a18d6e18d64
Created May 11, 2016 18:29
API Product Count through Pagination
require 'httparty'
LOGIN = 'my-store-code'
TOKEN = 'XXXXX'
response = HTTParty.get("https://api.jumpseller.com/v1/products/count.json?login=#{LOGIN}&authtoken=#{TOKEN}")
products_count = response.parsed_response["count"]
pages = products_count / 200 # the number of pages used for pagination.
last_pagination_count = products_count - pages * 200 # calculates the number of products present at the last pagination.
@tiagomatos
tiagomatos / productVariantListener_product_stock.js
Last active May 16, 2016 23:32
Jumpseller's Javascript method: productVariantListener to display Product stock info
<script type="text/javascript">
// more info at: https://jumpseller.com/support/javascript-library
var callbackFunction = function(event, productInfo){
if(!$.isEmptyObject(productInfo)){
console.log(productInfo);
alert('stock: ' + productInfo.stock + ', stock unlimited?:' + productInfo.stock_unlimited);
}
};
//update Product information with current variant
require 'uri'
require 'net/http'
require 'openssl'
require "benchmark"
HOST = 'api.jumpseller.com'
# uri = URI.parse("http://#{HOST}/landing/pricing?currency=CLP")
uri = URI.parse("http://#{HOST}/v1/products/{product_id}.json?login=XXX&authtoken=XXX")
// run in console for a Simple Product (without Product Variants):
// Jumpseller.addProductToCart(12345, 1, {}, {callback: addToCartCallback});
<script type="text/javascript">
function addToCartCallback(data) {
var sum = 0; // num of individual products in the cart.
$.each( data.products, function( index, product ){
sum += product.qty;
});
console.log('cart products sum:');
@tiagomatos
tiagomatos / gist:903f12b021cf113a9465fefe5cd44dcd
Last active May 3, 2017 22:02
Remove 'Shipping Address' from Checkout
<script type="text/javascript">
$( document ).ready(function() {
$('#shipping_address_same_as_shipping').hide(); // removes the checklist button
$('#shipping_address h2').text('{% t "Billing Address" %}'); // change text
});
</script>