Skip to content

Instantly share code, notes, and snippets.

View puneetkay's full-sized avatar

Puneet Kalra puneetkay

View GitHub Profile
@puneetkay
puneetkay / stripe_webhook.php
Created February 17, 2014 16:57
Stripe webhook for subscription.
<?php
require_once('./config.php');
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$postdata = file_get_contents("php://input");
$event = json_decode($postdata);
if ($event->type == 'invoice.payment_succeeded') {
$customer_id = $event->data->object->customer;
$customer = Stripe_Customer::retrieve($customer_id);
$invoice = Stripe_Invoice::retrieve($event->data->object->id);

Contract Killer

The popular open-source contract for web designers and developers by Stuff & Nonsense

  • Originally published: 23/12/2008
  • Revised date: 15/12/2013
  • Original post

@puneetkay
puneetkay / gist:71dcbc4ea13fb2763c0c
Created June 12, 2015 13:25
Limit string by words
function string_limit_words($string, $word_limit)
{
$words = explode(' ', $string, ($word_limit + 1));
if(count($words) > $word_limit)
array_pop($words);
return implode(' ', $words);
}
function $(q, parent) { return (parent || document).querySelector(q); }
@puneetkay
puneetkay / stopwords.php
Created October 27, 2015 16:37
Text to Keywords (start)
function extractCommonWords($string){
$stopWords = array('i','a','about','an','and','are','as','at','be','by','com','de','en','for','from','how','in','is','it','la','of','on','or','that','the','this','to','was','what','when','where','who','will','with','und','the','www');
$string = preg_replace('/ss+/i', '', $string);
$string = trim($string); // trim the string
$string = preg_replace('/[^a-zA-Z0-9 -]/', '', $string); // only take alphanumerical characters, but keep the spaces and dashes too…
$string = strtolower($string); // make it lowercase
preg_match_all('/\b.*?\b/i', $string, $matchWords);
$matchWords = $matchWords[0];
@puneetkay
puneetkay / download.php
Created October 31, 2013 12:55
Force download with php
<?php
function serve_file_resumable ($file, $contenttype = 'application/octet-stream') {
// Avoid sending unexpected errors to the client - we should be serving a file,
// we don't want to corrupt the data we send
@error_reporting(0);
// Make sure the files exists, otherwise we are wasting our time
if (!file_exists($file)) {
@puneetkay
puneetkay / gist:7811424
Created December 5, 2013 19:12
Tech Specs / Model
Class:
CSSParser
Functions:
1 - minifier()
2 - beautifier()
3 - parser()
Input variables:
$this->input->post('content') OR $_POST['content']
@puneetkay
puneetkay / queryString.js
Created December 13, 2013 10:43
Global JS function to get Query String
window.GetQueryString = function(q) {
return (function(a) {
if (a == "") return {};
var b = {};
for (var i = 0; i < a.length; ++i) {
var p = a[i].split('=');
if (p.length != 2) continue;
b[p[0]] = decodeURIComponent(p[1].replace(/\+/g, " "));
}
return b;
@puneetkay
puneetkay / jquery.center.js
Created December 13, 2013 10:42
Small jQuery plugin for center of parent or window! (Tweaked to set margin instead of position)
jQuery.fn.center = function(parent) {
if (parent) {
parent = $(this).parent();
} else {
parent = window;
}
$(this).css({
"margin-top": ((($(parent).height() - $(this).outerHeight()) / 2) + $(parent).scrollTop() + "px"),
"margin-left": ((($(parent).width() - $(this).outerWidth()) / 2) + $(parent).scrollLeft() + "px")
});
@puneetkay
puneetkay / Controller.php
Last active December 31, 2015 18:59
Get current controller and method in CI. Also, technique to get/manage dynamic global vars
<?php
class CI_Controller {
private static $instance;
public $data = array();
/**
* Constructor
*/