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 / madness.php
Last active June 15, 2018 09:55
One of the great things about PHP is you don't have the follow the rules when hacking stuff together. This makes map-building work easy to type up. However, since Golang there isn't much reason to use PHP anymore. Golang exceeds in every area from the stdlib to the speed and security of the application.
<?php
// Type casting is easy on weak languages
$a = (object) (array) (object) (array) (object) ["foo" => "bar"];
// PHP will happily iterate over an object (like Javascript)
foreach($a as $key => $value) {
print "$key = $value" . PHP_EOL;
}
@xeoncross
xeoncross / kjv_words.txt
Created February 23, 2016 19:33
Every word and symbol used in the 1611 KJV version of the bible along with its use count.
, 70683
the 63919
and 51696
of 34618
. 26145
to 13560
that 12915
: 12721
in 12667
he 10420
@amoilanen
amoilanen / speech_apis_demo.js
Last active October 6, 2016 07:17
Demo of the JavaScript speech API, can be pasted and executed in the browser console in Google Chrome
//Based on the demo https://gist.github.com/wesbos/cd16b8b1815825f111a2
(function(host) {
if (typeof speechSynthesis === 'undefined') {
console.warn('No speech syntesis feature available,'
+ 'calls to "say" will be ignored, try latest Google Chrome');
host.say = function() {};
return;
}
@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:

<?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;
@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
@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)
@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;
@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',
);
@irazasyed
irazasyed / downloadFileChunks.php
Last active November 2, 2023 08:36
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.