Skip to content

Instantly share code, notes, and snippets.

View mehdimehdi's full-sized avatar

Mehdi Ait Oufkir mehdimehdi

View GitHub Profile
<script type="text/javascript">
window._mfq = window._mfq || [];
(function() {
var mf = document.createElement("script");
mf.type = "text/javascript"; mf.async = true;
mf.src = "//cdn.mouseflow.com/projects/08ab6895-b885-4e9e-a827-5a8ece208524.js";
document.getElementsByTagName("head")[0].appendChild(mf);
})();
</script>
@mehdimehdi
mehdimehdi / internals.py
Created November 6, 2016 02:21
Handling SMS response from customers
""" more routes before, but does not affect the use case """
def follow_up_with_callee(twilio_data,event_id):
text = twilio_data.get('Body').upper()
task = import_module('switchboard.tasks')
if text == 'remove'.upper():
content = 'Great. will let him know.'
{% extends "base.html" %}
{% block content %}
<div>
Something special in my about page with a <button id="aboutbutton">about button</button>.
Something less special with some <button>other button</button> which is the same as the home.html button.
</div>
<script>
@mehdimehdi
mehdimehdi / gist:8482929
Created January 17, 2014 22:34
Histogram exercise
Build a command line tool which takes a CSV file-like input, and creates an histogram in ASCII
data = [(0,1),
(2, 4),
(4, 2),
(3, 3)]
Each row in the CSV is data which helps build the histogram. The first value is the column #, the second value is the value of bar in the histogram.
@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}]);
}
});