Skip to content

Instantly share code, notes, and snippets.

View jwv's full-sized avatar

Jonathan Vicente jwv

View GitHub Profile
@jwv
jwv / paypal_fees.php
Last active January 25, 2024 13:42
PHP: Paypal Fees
function paypalFees($sub_total, $round_fee) {
// Set Fee Rate Variables
$fee_percent = '3.4'; // Paypal's percentage rate per transaction (3.4% in UK)
$fee_cash = '0.20'; // Paypal's set cash amount per transaction (£0.20 in UK)
// Calculate Fees
$paypal_fee = ((($sub_total / 100) * $fee_percent) + $fee_cash);
if ($round_fee == true) {
@jwv
jwv / Highlight_Words_In_A_String.php
Created December 18, 2012 14:29
PHP: Highlight Words In A String
<?php
function highlight($astring, $aword) {
if (!is_array ($aword) || !is_string ($astring) || empty ($aword) ) {
return false;
}
$aword = implode ('|', $aword);
return preg_replace ('@\b('.$aword.')\b@si', '<strong style="background-color:red">$1</strong>', $astring);
}
@jwv
jwv / wp_list_table.php
Created May 10, 2022 09:43 — forked from donaldallen/wp_list_table
WP_List_Table example.
<?php
if ( ! class_exists('WP_List_Table')) {
require_once(ABSPATH . 'wp-admin/includes/class-wp-list-table.php');
}
class Events_List_Table extends WP_List_Table
{
function __construct()
{
global $status, $page;
@jwv
jwv / diffDayBetweenTwoDates.m
Created February 15, 2013 14:42
Objective-c: Calculate The Number Of Days Between Two Dates
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"MM-dd-yyy"];
// To use a specific start date
// NSDate *startDate = [formatter dateFromString:@"02-16-2013"];
// Start with todays date
NSDate *startDate = [NSDate date];
// End date
@jwv
jwv / slugify.php
Created July 31, 2021 11:48
Slugify String
// https://www.php.net/manual/en/transliterator.transliterate.php
function slugify($string, $separator = '-')
{
$slug = trim(strip_tags($string));
$slug = transliterator_transliterate('NFD; [:Nonspacing Mark:] Remove; NFC; Any-Latin; Latin-ASCII; Lower();', $slug);
$slug = preg_replace("/[^a-zA-Z0-9\\/_|+ -]/", '', $slug);
$slug = preg_replace("/[\\/_|+ -]+/", $separator, $slug);
$slug = trim($slug, $separator);
return $slug;
}
@jwv
jwv / certbot-manual-dns.sh
Last active November 13, 2020 11:42
Certbot Manual DNS
# Method 1
certbot certonly --manual --preferred-challenges dns --server https://acme-v02.api.letsencrypt.org/directory --manual-public-ip-logging-ok -d '*.<ypurdomain>' -d '<ypurdomain>'
# Method 2
certbot -d example.com --manual --preferred-challenges dns certonly
const admin = require("admin");
function getFirebaseUser(req, res, next) {
console.log("Check if request is authorized with Firebase ID token");
if (
!req.headers.authorization ||
!req.headers.authorization.startsWith("Bearer ")
) {
console.error(
"No Firebase ID token was passed as a Bearer token in the Authorization header.",
@jwv
jwv / .htaccess
Last active June 27, 2020 09:28
Apache: Maintenance mode
############################################
## 503 Maintenance mode
RewriteCond %{REQUEST_URI} !^/maintenance/
RewriteCond %{REMOTE_HOST} !^YOUR\.IP\.ADDRESS\.HERE$
RewriteCond %{REMOTE_HOST} !^127\.0\.0\.1$
RewriteRule .* index.php [R=503,L]
ErrorDocument 503 /maintenance/maintenance.html
# Keyboard
defaults write -g InitialKeyRepeat -int 10 # normal minimum is 15 (225 ms)
defaults write -g KeyRepeat -int 1 # normal minimum is 2 (30 ms)
@jwv
jwv / create-ssl-cert.bat
Last active September 21, 2018 22:44
CMD - Create SSL Cert NGINX
@ECHO OFF
ECHO Creating SSL Cert...
set NGINX_HOME=C:\nginx114
set OPENSSL_HOME="C:\Program Files\OpenSSL-Win64\bin"
set PATH=%PHP_HOME%;%PATH%
openssl req -x509 -nodes -days 36500 -newkey rsa:4096 -keyout %NGINX_HOME%/ssl/%1.key -out %NGINX_HOME%/ssl/%1.crt
ECHO SSL Cert Created...
ECHO %NGINX_HOME%/conf/%1.key
ECHO %NGINX_HOME%/conf/%1.crt