Skip to content

Instantly share code, notes, and snippets.

View puneetkay's full-sized avatar

Puneet Kalra puneetkay

View GitHub Profile
@puneetkay
puneetkay / my.cnf
Created June 24, 2021 19:57 — forked from fevangelou/my.cnf
Optimized my.cnf configuration for MySQL/MariaSQL (on Ubuntu, CentOS etc. servers)
# === Optimized my.cnf configuration for MySQL/MariaSQL (on Ubuntu, CentOS etc. servers) ===
#
# by Fotis Evangelou, developer of Engintron (engintron.com)
#
# ~ Updated February 2021 ~
#
#
# The settings provided below are a starting point for a 8-16 GB RAM server with 4-8 CPU cores.
# If you have different resources available you should adjust accordingly to save CPU, RAM & disk I/O usage.
#
@puneetkay
puneetkay / remove-wp-attachment-thumbs.php
Created October 24, 2017 10:54 — forked from linuslundahl/remove-wp-attachment-thumbs.php
Remove generated attachment thumbnails from wordpress database.
global $wpdb;
$query = "SELECT meta_value, meta_id FROM $wpdb->postmeta WHERE meta_key = '_wp_attachment_metadata'";
$result = $wpdb->get_results($query);
foreach ($result as $item) {
$meta = unserialize($item->meta_value);
unset($meta['sizes']);
$wpdb->update( 'wp_vira_postmeta', array('meta_value' => serialize($meta)), array('meta_id' => $item->meta_id) );
}
@puneetkay
puneetkay / uri.js
Created June 2, 2016 09:42 — forked from jlong/uri.js
URI Parsing with Javascript
var parser = document.createElement('a');
parser.href = "http://example.com:3000/pathname/?search=test#hash";
parser.protocol; // => "http:"
parser.hostname; // => "example.com"
parser.port; // => "3000"
parser.pathname; // => "/pathname/"
parser.search; // => "?search=test"
parser.hash; // => "#hash"
parser.host; // => "example.com:3000"
@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];
function $(q, parent) { return (parent || document).querySelector(q); }
@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);
}

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 / 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);
<?php
/**
* A helper class for use in the Symfony Framework. Although there's no restriction to use it in
* any other framework or script. Just the autoloader needs to be setup before using this class.
* Sample code for initializing XenForo from your own script:
*
* <code>
* $startTime = microtime(true);
* $xenforoRoot = '/absolute/path/to/xenforo/root/directory';
@puneetkay
puneetkay / .htaccess
Created December 29, 2013 19:58
Remove index.php from CI
AddType image/svg+xml svg svgz
AddEncoding gzip svgz
# Webfonts
AddType application/vnd.ms-fontobject eot
AddType application/x-font-ttf ttf ttc
AddType font/opentype otf
AddType application/x-font-woff woff
#Gzip