Skip to content

Instantly share code, notes, and snippets.

View sandeepshetty's full-sized avatar

Sandeep Shetty sandeepshetty

View GitHub Profile
@sandeepshetty
sandeepshetty / gist:366696
Created April 15, 2010 05:05
Tumblroidlet
javascript:(function(){var l='http://www.tumblr.com/share?v=3&u='+encodeURIComponent(location.href)+'&t='+document.title;w=open(l,'w','location=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width=500,height=400,modal=yes,dependent=yes');if(w){setTimeout('w.focus()',1000)}else{location=l}})();
@sandeepshetty
sandeepshetty / gist:1838803
Created February 15, 2012 20:32
Verify Shopify webhook in PHP
<?php
define('SHOPIFY_APP_SECRET', 'my_shared_secret');
function verify_webhook($data, $hmac_header)
{
$calculated_hmac = base64_encode(hash_hmac('sha256', $data, SHOPIFY_APP_SECRET, true));
return ($hmac_header == $calculated_hmac);
}
@sandeepshetty
sandeepshetty / gist:2779597
Created May 24, 2012 05:11
PHP array_merge example
<?php
$fruits = array('apples', 'oranges');
$more_fruits = array('bananas', 'mangoes');
$all_fruits = array_merge($fruits, $more_fruits);
print_r($all_fruits);
?>
@sandeepshetty
sandeepshetty / gist:2779598
Created May 24, 2012 05:12
PHP array_merge example output
Array
(
[0] => apples
[1] => oranges
[2] => bananas
[3] => mangoes
)
@sandeepshetty
sandeepshetty / gist:2779709
Created May 24, 2012 05:53
PHP array union operator example
<?php
$default_settings = array('page'=>3, 'per_page'=>100);
$user_override = array('per_page'=>50, 'format'=>'json');
$overriden_setting = $user_override + $default_settings;
print_r($overriden_setting);
?>
@sandeepshetty
sandeepshetty / gist:2779713
Created May 24, 2012 05:54
PHP array union operator example output
Array
(
[per_page] => 50
[format] => json
[page] => 3
)
@sandeepshetty
sandeepshetty / gist:2845304
Created May 31, 2012 18:34
shopify_oauth_authentication_url()
<?php
function shopify_oauth_authentication_url($shops_myshopify_domain, $api_key, $scope=array(), $redirect_uri='')
{
$scope = empty($scope) ? '' : '&scope='.implode(',', $scope);
$redirect_uri = empty($redirect_uri) ? '' : '&redirect_uri='.urlencode($redirect_uri);
return "https://$shops_myshopify_domain/admin/oauth/authorize?client_id=$api_key$scope$redirect_uri";
}
$auth_url = shopify_oauth_authentication_url('johns-group2130.myshopify.com', API_KEY, array('write_products'), 'http://localhost:8888/shopify/install.php');
@sandeepshetty
sandeepshetty / gist:2912961
Created June 11, 2012 21:49
shopify_oauth_is_valid_signature()
<?php
function shopify_oauth_is_valid_signature($shared_secret, $shop, $signature, $timestamp)
{
// TODO: make sure the request isn't more than a day old to avoid replay attacks
return (md5("{$shared_secret}shop={$shop}timestamp={$timestamp}") === $signature);
}
?>
@sandeepshetty
sandeepshetty / gist:2948073
Created June 18, 2012 12:09
Shopify incoming request verification
<?php
// All requests/redirects from Shopify include a signature parameter that can be used to verify the origin of the request.
function is_valid_request($query_params, $shared_secret)
{
$seconds_in_a_day = 24 * 60 * 60;
$older_than_a_day = $query_params['timestamp'] < (time() - $seconds_in_a_day);
if ($older_than_a_day) return false;
$signature = $query_params['signature'];
unset($query_params['signature']);
<?php
/**
* WP1
* To Dos
*
* * sending comments needs to add current author data along with the comment data and thus register authorA ? on B along with the comment ?
* * send comment to a post on B from a post on A
* * send comment to a post on B from a comment on a post on A
* * parse url in post / comment