Skip to content

Instantly share code, notes, and snippets.

View mehdimehdi's full-sized avatar

Mehdi Ait Oufkir mehdimehdi

View GitHub Profile
@mehdimehdi
mehdimehdi / sso-login.html
Last active January 2, 2016 16:09
Log a user in (create an account if user does not exists)
<!DOCTYPE HTML>
<html>
<body>
<script>
var _pt_pre_config = {
auth_request: "eyJpZCI6IjIiLCJmaXJzdF9uYW1lIjoiSm9obiIsImxhc3RfbmFtZSI6IkRvZSIsImVtYWlsIjoiam9obi5kb2VAZXhhbXBsZS5uZXQiLCJhdmF0YXJfbGluayI6Imh0dHA6XC9cL3MzLmFtYXpvbmF3cy5jb21cL3B1bmNodGFiLXN0YXRpY1wvenp6enp6XC9pbWdcL3RlYW1cL2xld29sZi5qcGcifQ==",
signature: "9660b0ea6c6abc916ea055a6fdd12c76cb3a4dfb",
timestamp: "1389384230",
client_id: "2128281015"
};
@mehdimehdi
mehdimehdi / sso-login.php
Last active January 2, 2016 16:09
Log a user in (create an account if user does not exists)
<?php
define ('PUNCHTAB_CLIENT_ID', '2128281015'); //client_id
define ('PUNCHTAB_SECRET_KEY', '< YOUR SECRET KEY >');
define ('PUNCHTAB_ACCESS_KEY', 'c370b56450e41a8f689fffb2374e7ef4'); //key
$user = array('id' => '2', 'first_name' => 'John', 'last_name' => 'Doe', 'email' => 'john.doe@example.net', 'avatar_link' => 'http://s3.amazonaws.com/punchtab-static/zzzzzz/img/team/lewolf.jpg');
$auth_request = base64_encode(json_encode($user));
$timestamp=time();
$signature = hash_hmac('sha1', "$auth_request $timestamp", PUNCHTAB_SECRET_KEY);
@mehdimehdi
mehdimehdi / sso-login.py
Last active January 2, 2016 01:29
Log a user in (create an account if user does not exists)
import requests
import base64
import hashlib
import hmac
import simplejson
import time
PUNCHTAB_CLIENT_ID = '2128281015' #client_id
PUNCHTAB_SECRET_KEY = '<YOUR SECRET KEY>'
PUNCHTAB_ACCESS_KEY = 'c370b56450e41a8f689fffb2374e7ef4' #key
@mehdimehdi
mehdimehdi / login-status
Last active January 2, 2016 01:28
Checking login status
$curl "https://api.punchtab.com/v1/auth/status?token=ll&key=c370b56450e41a8f689fffb2374e7ef4"
{
"status": "disconnected"
}
@mehdimehdi
mehdimehdi / clean.js
Last active December 31, 2015 07:19
Cleaning up old documents in large collection
//getting the punchtab db to do the real db operations..
var punchtabDb = db.getSiblingDB('punchtab');
//the date to start from
var oldestDoc = punchtabDb.track.find({},{date_created:1}).sort({date_created : 1}).limit(1).toArray()[0];
var someOldDate = oldestDoc['date_created'];
var sleepAmount = 10 * 1000; //ten second
var failSafeDate = new Date(2013,05,13);
@mehdimehdi
mehdimehdi / gist:7013024
Created October 16, 2013 19:04
BazaarVoice <-> PunchTab integration
PT.event.bind('main.comment', function (response) {
if (response && response.commentID) {
_ptq.push(['review', {points: 100, ref_id: response.commentID}]);
}
});
@mehdimehdi
mehdimehdi / gist:6731916
Created September 27, 2013 17:17
Dotcloud push
# upload /Users/mehdi/Documents/attila ssh://dotcloud@uploader.dotcloud.com:443/analytics
# git
Warning: Permanently added '[uploader.dotcloud.com]:443,[23.21.128.228]:443' (RSA) to the list of known hosts.
Everything up-to-date
17:13:58 ---> Deploy of "analytics" scheduled for revision git-574d320 at 2013-09-27 17:13:58
17:13:58 ---> Building the application...
17:13:58 [extract] Build started for revision git-574d320-1 (clean build)
17:14:01 [extract] I am snapshotsworker_02/ec2-184-73-114-244, and I will be your builder today.
17:14:03 [extract] stdin: is not a tty
17:14:03 [extract] Get:1 http://us-east-1.ec2.archive.ubuntu.com.s3.amazonaws.com lucid Release.gpg [189B]
@mehdimehdi
mehdimehdi / gist:6502903
Created September 9, 2013 23:28
Connect to the loyalty program JS snippet (need to create a button with the id "connect-button"
var connectButton = PT.dom.$("connect-button");
PT.widget.connect.attachConnect(connectButton);
@mehdimehdi
mehdimehdi / gist:6500841
Created September 9, 2013 20:10
This is how to get the access token.
window.ptReady = window.ptReady || [];
window.ptReady.push(function(){
PT.event.bind('user.connected', function(event){
console.log(event.accessToken);//<- this is the token you need to call our API
});
});
<div id="rwd_tab" class="left bottom">
<div id="red_tab"></div>
<a id="pwd_below_tab" target="_blank" href="//www.punchtab.com?src=pwd-by-tab&amp;src_key=">
</a>
</div>