Skip to content

Instantly share code, notes, and snippets.

<?php
// prevent direct access, only index.php can include this file
defined ( 'STRIPE_SECRET_KEY' ) || exit ( 'Direct access not allowed' . PHP_EOL );
use \Stripe\Stripe;
use \Stripe\Customer;
use \Stripe\Charge;
Stripe::setApiKey(STRIPE_SECRET_KEY);
<?php
/**
* Get the user country code with package
*
* Requires geoiplookup package installed
* @link http://manpages.ubuntu.com/manpages/trusty/man1/geoiplookup.1.html
* @param $ip user IP string
* @param $args Array (optional parameters)
*/
@elhardoum
elhardoum / alexa.py
Last active October 3, 2017 20:58 — forked from masnun/alexa.py
Python One-liner to get your site's Alexa Rank - https://samelh.com/blog/2017/10/01/get-alexa-site-rank-python-php-javascript/
#!/usr/bin/env python
import urllib, sys, re
xml = urllib.urlopen('http://data.alexa.com/data?cli=10&dat=s&url=%s'%sys.argv[1]).read()
try: rank = int(re.search(r'<POPULARITY[^>]*TEXT="(\d+)"', xml).groups()[0])
except: rank = -1
print 'Your rank for %s is %d!\n' % (sys.argv[1], rank)
@elhardoum
elhardoum / attachDomEvent.js
Last active May 18, 2018 12:55
Attach multiple events (click, load, etc) to a DOM element
(function(){
'use strict';
Object.prototype.attachDomEvent = function(eventName, callback)
{
eventName = eventName.replace(/^on/g, '');
if ( window.addEventListener ) {
this.addEventListener(eventName, callback, false);
} else if ( window.attachEvent ) {
<?php
use Predis\Client as PredisClient;
include __DIR__ . '/vendor/autoload.php';
function redis() {
global $Redis;
if ( !isset($Redis) || !$Redis instanceof PredisClient ) {
import json
import urllib
downloader = urllib.URLopener()
# start by getting the full list of videos
with open('items.json') as json_data:
items = json.load(json_data)
# where to save the videos (directory)
save_to_dir = './'
@elhardoum
elhardoum / mc-feed.php
Created October 12, 2017 22:43
https://samelh.com/blog/?p=582 - Tweak MailChimp RSS Feeds to add the featured image, excerpt and a read more button.
<?php
/*
Plugin Name: Tweak MailChimp Feeds RSS
Plugin URI: https://samelh.com/blog
Description: Tweak MailChimp RSS Feeds to add the featured image, excerpt and a read more button.
Author: Samuel Elh
Version: 0.1
Author URI: https://go.samelh.com/buy-me-a-coffee
*/
<?php
require __DIR__ . '/vendor/autoload.php';
use \DrewM\MailChimp\MailChimp;
$mc = new MailChimp('<your-mailchimp-api-key>');
// list ID
// When a user unsubscribes from the list, they cannot be subscribed again
// via the API, so use a unique list for this mailing purpose
var start = +new Date, d, chrono
setInterval(function()
{
d = new Date( +new Date - start )
chrono = (''+d).match( /\d+:\d+(?= )/g )[0] + ':' + Math.floor(d.getMilliseconds()/100)
document.body.innerHTML = chrono.replace(/(\d+)/g, '<span>$1</span>').replace(':', '\'').replace(':', '"')
}, 100)