Skip to content

Instantly share code, notes, and snippets.

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

Jerry Martinez jmwebservices

🏠
Working from home
View GitHub Profile
@jmwebservices
jmwebservices / convert-pgp-to-ssh.sh
Created January 19, 2023 00:02 — forked from mdellavo/convert-pgp-to-ssh.sh
Convert PGP Public Key to OpenSSH
# import the public key
gpg --import ../alice.asc
gpg --export $KEYID | openpgp2ssh $KEYID
@jmwebservices
jmwebservices / strpos-chunk.php
Last active December 4, 2019 17:55
Show that strpos() on a chunk using substr() is more efficient than on the whole for large strings.
function find( ?string $string )
{
static $found = 0;
if( null === $string ) return $found;
$found += 0 === strpos( $string, BOM_UTF8 );
$found += 0 === strpos( $string, BOM_UTF16_BE );
$found += 0 === strpos( $string, BOM_UTF16_LE );
$found += 0 === strpos( $string, BOM_UTF32_BE );
@jmwebservices
jmwebservices / Readme.md
Created November 19, 2019 04:28
PHP fopen Modes Impact on Read, Write and Seek

PHP fopen Modes Impact on Read, Write and Seek

Use the following table as a desk reference for the various fopen modes and how they impact read, write and seek.

Mode Read Write Seek
r ✔️ ✔️
r+ ✔️ ✔️ ✔️
w ✔️ ✔️
w+ ✔️ ✔️ ✔️
@jmwebservices
jmwebservices / Str.php
Created May 7, 2019 02:24
Create Multibyte Safe Random String (PHP 7+)
<?php
class Str
{
/**
* Generate and return a random string having a specified length and composed of a specified
* set of characters.
*
* <i>This method is multibyte safe.</i>
@jmwebservices
jmwebservices / Readme.md
Last active March 20, 2019 20:09
JavaScript Own vs Proto vs [Non-]Enumerable Getters

JavaScript Property Type Getters

Use the following table as a desk reference for the various ways to obtain properties of objects and which properties each method returns.

Method/Operator/Loop own proto enumerable non-enumerable
for prop in obj ✔️ ✔️ ✔️
prop in obj ✔️ ✔️ ✔️ ✔️
obj.hasOwnProperty( prop ) ✔️ ✔️ ✔️
obj.propertyIsEnumerable( prop ) ✔️ ✔️
@jmwebservices
jmwebservices / rrmdir.php
Last active November 3, 2022 20:49 — forked from liconti/rrmdir.php
PHP recursive rmdir
<?php
/**
* Recursively empty and delete a directory
*
* @param string $path
* @ref https://gist.github.com/jmwebservices/986d9b975eb4deafcb5e2415665f8877
*/
function rrmdir( string $path ) : void
{
@jmwebservices
jmwebservices / bench.php
Created August 24, 2018 09:56 — forked from nikic/bench.php
Benchmark of call_user_func_array vs switch optimization vs argument unpacking syntax
<?php error_reporting(E_ALL);
function test() {}
$nIter = 1000000;
$argNums = [0, 1, 2, 3, 4, 5, 100];
$func = 'test';
foreach ($argNums as $argNum) {
@jmwebservices
jmwebservices / DatePeriod_Filter.php
Last active July 19, 2018 23:01
Apply filters over the iterable values of a DatePeriod object.
<?php
/**
* Apply filters over the iterable values of a DatePeriod object
*
* @method self monday Include Mondays while iterating the DatePeriod
* @method self tuesday Include Tuesdays while iterating the DatePeriod
* @method self wednesday Include Wednesdays while iterating the DatePeriod
* @method self thursday Include Thursdays while iterating the DatePeriod
* @method self friday Include Fridays while iterating the DatePeriod
* @method self saturday Include Saturdays while iterating the DatePeriod