Skip to content

Instantly share code, notes, and snippets.

View ahmu83's full-sized avatar
🎯
Focusing

Ahmad Karim ahmu83

🎯
Focusing
View GitHub Profile
@adilapapaya
adilapapaya / README
Last active June 27, 2020 11:58
Export Table Data to CSV using Javascript
Example code for exporting data in a table to a csv file.
@stut
stut / gist:6438640
Last active November 3, 2020 03:00
100 first names and 100 last names.
<?php
$first_names = array(
'Abigail', 'Alice', 'Amber', 'Amelia', 'Amy', 'Ava', 'Brooke',
'Caitlin', 'Charlotte', 'Chloe', 'Daisy', 'Elizabeth', 'Ella', 'Ellie',
'Emily', 'Emma', 'Erin', 'Eva', 'Evie', 'Freya', 'Grace', 'Hannah',
'Holly', 'Imogen', 'Isabel', 'Isabella', 'Isabelle', 'Isla', 'Jasmine',
'Jessica', 'Katie', 'Keira', 'Leah', 'Lilly', 'Lily', 'Lola', 'Lucy',
'Matilda', 'Megan', 'Mia', 'Millie', 'Molly', 'Olivia', 'Phoebe',
'Poppy', 'Ruby', 'Scarlett', 'Sophia', 'Sophie', 'Summer', 'Adam',
'Alex', 'Alexander', 'Alfie', 'Archie', 'Benjamin', 'Callum',
@axwax
axwax / addToGoogleCalendar.php
Created December 5, 2012 14:43
add event to google calendar
<?php
// add event to google calendar
echo '<a href="' . addToGoogleCalendar("Let's test this", "next wednesday 2pm", "next wednesday 4pm", "right here, right now", "bla blah rhubarb http://axwax.de") . '">next weds 2pm</a><br/>';
echo '<a href="' . addToGoogleCalendar("Breakfast at Tiffany's", "tomorrow 8am") . '">Breakfast at Tiffany\'s</a>';
function addToGoogleCalendar($title='', $startdate='', $enddate='', $location='', $details='')
{
$startdate = ($startdate ? $startdate : time());
$startdate = (is_numeric($startdate) ? $startdate : strtotime($startdate));
@jmoz
jmoz / DomXpath.php
Created June 26, 2012 14:49
DomXpath example
<?php
/**
* @author James Morris <james@jmoz.co.uk>
*/
$html = <<<'EOF'
<html>
<body>
<h1>Foo</h1>
<div id="content">
@ninnypants
ninnypants / remove-empty-p.php
Last active January 3, 2023 01:11
Remove empty p tags from WordPress posts
<?php
add_filter( 'the_content', 'remove_empty_p', 20, 1 );
function remove_empty_p( $content ){
// clean up p tags around block elements
$content = preg_replace( array(
'#<p>\s*<(div|aside|section|article|header|footer)#',
'#</(div|aside|section|article|header|footer)>\s*</p>#',
'#</(div|aside|section|article|header|footer)>\s*<br ?/?>#',
'#<(div|aside|section|article|header|footer)(.*?)>\s*</p>#',
'#<p>\s*</(div|aside|section|article|header|footer)#',
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ ^$1 [N]
@zecka
zecka / html-purifier-example-use.php
Created May 27, 2020 12:51
Example use of HTMLPurifier PHP
<?php
// composer install ezyang/htmlpurifier
require 'vendor/autoload.php';
$config = HTMLPurifier_Config::createDefault();
$config->set('HTML.AllowedElements', 'a,i,b,p,div,strong,h1,h2,h3,h4,h5,ol,ul,li,br');
$config->set('HTML.AllowedAttributes', 'href,title,target,name');
$config->set('HTML.Attr.Name.UseCDATA', true);
$config->set('AutoFormat.RemoveEmpty.RemoveNbsp', true);
$config->set('Attr.AllowedFrameTargets', ['_blank']);
@wpsmith
wpsmith / sanitize_phone.php
Created June 5, 2014 17:00
PHP: Sanitize & Format US Phone Numbers
<?php
function sanitize_phone( $phone, $international = false ) {
$format = "/(?:(?:\+?1\s*(?:[.-]\s*)?)?(?:\(\s*([2-9]1[02-9]|[2-9][02-8]1|[2-9][02-8][02-9])\s*\)|([2-9]1[02-9]|[2-9][02-8]1|[2-9][02-8][02-9]))\s*(?:[.-]\s*)?)?([2-9]1[02-9]|[2-9][02-9]1|[2-9][02-9]{2})\s*(?:[.-]\s*)?([0-9]{4})(?:\s*(?:#|x\.?|ext\.?|extension)\s*(\d+))?$/";
$alt_format = '/^(\+\s*)?((0{0,2}1{1,3}[^\d]+)?\(?\s*([2-9][0-9]{2})\s*[^\d]?\s*([2-9][0-9]{2})\s*[^\d]?\s*([\d]{4})){1}(\s*([[:alpha:]#][^\d]*\d.*))?$/';
// Trim & Clean extension
$phone = trim( $phone );
$phone = preg_replace( '/\s+(#|x|ext(ension)?)\.?:?\s*(\d+)/', ' ext \3', $phone );
@mikejolley
mikejolley / gist:3097073
Last active January 18, 2024 17:54
WooCommerce - Unhook/Disable emails
/**
* Code goes in functions.php or a custom plugin.
*/
add_action( 'woocommerce_email', 'unhook_those_pesky_emails' );
function unhook_those_pesky_emails( $email_class ) {
/**
* Hooks for sending emails during store events
**/
@phuze
phuze / dropbox-php-auth.md
Last active February 2, 2024 13:46
Dropbox API V2: PHP Authentication Process

Effective September 2021, Dropbox will be deprecating long-lived access tokens.

This GIST generally describes how to authenticate requests to Dropbox API v2, for anyone working on a server-side PHP Dropbox implementation.

It's important to understand three types of codes you'll encounter:

  1. Access Code - this is a one-time code that represents user-granted app access.
  2. Access Token - this is short-lived token that provides access to Dropbox API endpoints.
  3. Refresh Token - this is a long-lived token that allows you to fetch a fresh Access Token.