Skip to content

Instantly share code, notes, and snippets.

View johnabela's full-sized avatar
🏠
Working from home

John Abela johnabela

🏠
Working from home
View GitHub Profile
@xeoncross
xeoncross / timezone.php
Created September 8, 2011 18:43
The perfect TimeZone selectbox list for PHP 5.3+
<?php
$regions = array(
'Africa' => DateTimeZone::AFRICA,
'America' => DateTimeZone::AMERICA,
'Antarctica' => DateTimeZone::ANTARCTICA,
'Aisa' => DateTimeZone::ASIA,
'Atlantic' => DateTimeZone::ATLANTIC,
'Europe' => DateTimeZone::EUROPE,
'Indian' => DateTimeZone::INDIAN,
'Pacific' => DateTimeZone::PACIFIC
@uu59
uu59 / gist:2375573
Created April 13, 2012 10:09
filter_var vs. preg_match
<?php
// http://nob-log.info/2012/04/12/phper-filter-validate-email/
$times = 10000;
$result = array();
// preg_match
// regexp is stolen from:
// https://github.com/php/php-src/blob/master/ext/filter/logical_filters.c#L525
@jbroadway
jbroadway / Slimdown.md
Last active February 5, 2024 10:43
Slimdown - A simple regex-based Markdown parser.
@irazasyed
irazasyed / downloadFileChunks.php
Last active May 3, 2024 09:57
PHP: File downloader function - Downloading files in chunks.
<?php
/**
* Download helper to download files in chunks and save it.
*
* @author Syed I.R <syed@lukonet.com>
* @link https://github.com/irazasyed
*
* @param string $srcName Source Path/URL to the file you want to download
* @param string $dstName Destination Path to save your file
* @param integer $chunkSize (Optional) How many bytes to download per chunk (In MB). Defaults to 1 MB.
@jonathantneal
jonathantneal / facebook.php
Created January 6, 2014 10:00
Simple Facebook PHP API
<?php
class FacebookBase {
public static $curlOpts = array(
CURLOPT_CONNECTTIMEOUT => 10,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 60,
CURLOPT_USERAGENT => 'facebook-php',
);
@clnmcgrw
clnmcgrw / gist:9086505
Last active November 25, 2021 11:16
Google Maps API Geocode Example - PHP/JSON
<?php
// address to map
$map_address = "";
$url = "http://maps.googleapis.com/maps/api/geocode/json?sensor=false&address=".urlencode($map_address);
$lat_long = get_object_vars(json_decode(file_get_contents($url)));
// pick out what we need (lat,lng)
$lat_long = $lat_long['results'][0]->geometry->location->lat . "," . $lat_long['results'][0]->geometry->location->lng;
@massiws
massiws / gist:9593008
Last active August 17, 2022 05:15
PHP Count the number of working days between two dates.
<?php
/**
* Count the number of working days between two dates.
*
* This function calculate the number of working days between two given dates,
* taking account of the Public festivities, Easter and Easter Morning days,
* the day of the Patron Saint (if any) and the working Saturday.
*
* @param string $date1 Start date ('YYYY-MM-DD' format)
@neo22s
neo22s / formatcurrency.php
Created March 18, 2014 14:41
NumberFormatter formatCurrency alternative
<?php
error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE);
ini_set('display_errors', 1);
function formatcurrency($floatcurr, $curr = 'USD')
{
/**
* A list of the ISO 4217 currency codes with symbol,format and symbol order
<?php
// input misspelled word
$input = 'carrrot';
// array of words to check against
$words = array('apple','pineapple','banana','orange',
'radish','carrot','pea','bean','potato');
// no shortest distance found, yet
$shortest = -1;
@johndellavecchia
johndellavecchia / Stripe-Checkout-PHP.md
Last active June 15, 2018 10:09
Stripe Checkout v2 PHP donation example

Stripe Checkout with Variable Donation Amount

This example uses techniques to implement a donation page with Stripe Checkout and PHP. It includes a variable amount input, quick-add amount buttons, basic form validation, ajax card charge, error handling on the response, UI for processing during submission, and ARIA accessibility enhancements.

ExpressionEngine Notes

If you use ExpressionEngine, make sure to include CSRF in your form and ajax post:

Add a hidden input to the form: