Skip to content

Instantly share code, notes, and snippets.

View Xhynk's full-sized avatar

Alexander Demchak Xhynk

View GitHub Profile
@Xhynk
Xhynk / substr_html.php
Last active January 23, 2021 04:02
Get a substring from an HTML string that includes HTML tags. Tags that are interrupted in the tag are removed, all others are auto-closed if necessary
<?php
// $start is option, but it will trim the HTML. Recommended to keep at 0 and use for start of strings only.
function substr_html( string $str, int $start = 0, int $end, array $replace_tags = array(), string $encoding = 'utf-8', bool $remove_body = true ){
$max = strlen($str);
$out = $last_caret = '';
for( $i = $characters = $gt = 0, $lt = -1; $characters < $end && $i < $max; $i++ ){
$char = $str[$i];
$entity = false;
@Xhynk
Xhynk / Code.gs
Last active February 6, 2023 00:18
A simple Google Apps Script to submit a Google Sheets powered timesheet: https://docs.google.com/spreadsheets/d/1D-YWjt_Zl8WrAuicmUKZsMzSpEOwv1vYL06dBdObyb4/
/*-----------------------------------*\
Written with 💖 by @Xhynk
Donate:
https://xhynk.com/#donate
\*-----------------------------------*/
// Example Google Sheets Timesheet: https://docs.google.com/spreadsheets/d/1D-YWjt_Zl8WrAuicmUKZsMzSpEOwv1vYL06dBdObyb4/
function submitTimesheet(e){
@Xhynk
Xhynk / stack_exchange_data.php
Created August 21, 2020 21:44
A simple PHP function to help grab your most recent Stack Exchange values for use in your website.
<?php
function get_stack_exchange_data( int $stack_exchange_id, bool $force_refresh = false, string $cache_dir = __DIR__ . '/stack-exchange' ){
$max_age = 1800;
$api_url = sprintf( 'https://api.stackexchange.com/2.2/users/%d/associated', $stack_exchange_id );
$cache_name = sprintf( '%s/%d.txt', $cache_dir, $stack_exchange_id );
if( !is_dir($cache_dir) )
mkdir( $cache_dir );
if( !file_exists($cache_name) || (file_exists($cache_name) && filemtime($cache_name) < ( time() - $max_age )) ){
@Xhynk
Xhynk / stripe_live_products_to_test.php
Created July 8, 2020 20:56
A simple method to copy live Stripe products (and their plans) to your Testing area. The `$illegal_params` array can be modified as needed, and more fields can be added to both creation methods. In my case I just needed the Product Name and Metadata, and have a lot of old plans, so figured I'd get all the data, and remove the illegal or unused p…
<?php
// Start a Stripe Client for Live and Test
$stripe_live = new \Stripe\StripeClient( 'YOUR_LIVE_SECRET' );
$stripe_test = new \Stripe\StripeClient( 'YOUR_TEST_SECRET' );
// Fetch All Products
$live_products = $stripe_live->products->all(['limit' => 100]);
// Start an array to dump our results
$dump = array();
@Xhynk
Xhynk / custom-functions.php
Created October 12, 2018 06:49
Update Bulk Content Masks
add_action( 'init', 'insert_content_masks' );
function insert_content_masks(){
$array_of_mask_urls = array(
'https://landing-page.com/page-1',
'https://landing-page.com/page-2',
'https://landing-page.com/page-3',
// …
'https://landing-page.com/page-xxx',
);
04fba7cbe28b437ab8ff2a809eddb210e14a44be494d34ceeb2b1557d501c9405b4eb0869eb72a7428916e7a129072182ae097e07104321330f07e13fcae4b8815
@Xhynk
Xhynk / set-featured-image-as-background-min.php
Last active July 20, 2017 20:56
Set Featured Image as Background/Header on Cafe Pro