This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$client = new GuzzleHttp\Client(); | |
// Ref: https://guzzle.readthedocs.io/en/latest/request-options.html#sink-option | |
$client->request('GET', 'http://example.com', [ | |
'sink' => '/tmp/' . sha1(file_get_contents('https://example.com')) | |
]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function getPDOInstance($host, $name, $user, $password) | |
{ | |
$dsn = str_replace( | |
['{HOST}', '{NAME}'], | |
[$host, $name], | |
'mysql:host={HOST};dbname={NAME};charset=utf8mb4' | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function($, undefined) { | |
'use strict'; | |
if (window.className !== undefined) { | |
return; | |
} | |
window.className = { | |
init: function() { | |
// code... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
defined( 'ABSPATH' ) || exit; | |
class WC_REST_API_Key { | |
// See WC_Auth::create_keys | |
public static function create( $user_id, $description, $permissions = 'read' ) { | |
global $wpdb; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (! function_exists('stop_before')) { | |
function stop_before(callable $func, DateTimeInterface $dt) | |
{ | |
$tz = $dt->getTimezone(); | |
$now = new DateTime('now', $tz); | |
if ($now > $dt) { | |
call_user_func($func); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
set -euo pipefail | |
# Ref: | |
# * https://stackoverflow.com/a/44992513 | |
# * https://github.com/jwiegley/git-scripts/blob/master/git-pr | |
test -z $1 && echo "Merge request number required." 1>&2 && exit 1 | |
git fetch ${2:-origin} merge-requests/$1/head:mr-$1 && git checkout mr-$1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
set -euo pipefail | |
echo "Updating Homebrew..." | |
brew update && brew upgrade && brew cleanup | |
echo "Updating Composer..." | |
composer self-update --clean-backups && composer g update && composer g dump-autoload | |
#composer g clear-cache |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
set -euo pipefail | |
docker stop $(docker ps -aq) | |
docker rm $(docker ps -aq) | |
docker rmi $(docker images --format "{{.Repository}}" | grep 'bsdock') | |
[[ -f "$PWD/docker-compose.yml" ]] && docker-compose up -d --build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Set cipher method | |
$cipherMethod = 'AES-256-CBC'; | |
// Set encryption key | |
// The key length must be 256 bits long | |
$key = (empty($key)) ? openssl_random_pseudo_bytes(32) : '...'; | |
// Set initialization vector | |
$iv = (empty($iv)) ? openssl_random_pseudo_bytes(openssl_cipher_iv_length($cipherMethod)) : '...'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* An AES encryption implementation in PHP with Mcrypt module. | |
* | |
* Key length is 256, CBC mode, and use PKCS#7 padding. | |
* | |
* Example: | |
* $aes = new McryptAes256; | |
* $encryptedString = $aes->encrypt($rawString); | |
* $decryptedString = $aes->decrypt($encryptedString); |