Skip to content

Instantly share code, notes, and snippets.

View UVLabs's full-sized avatar
🏠
Probably coding

Uriahs Victor UVLabs

🏠
Probably coding
View GitHub Profile
@UVLabs
UVLabs / detect-highlighted-text.html
Last active February 11, 2024 04:28
Detect highlighted text using JavaScript
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Selected Text Example</title>
<script>
// Adapted from: https://jsfiddle.net/timdown/SW54T/
// Fixed bug where alert would show twice: once when text is selected and again after page is cicked when exiting alert.
function getSelectedText() {
@UVLabs
UVLabs / add_xcd_equivalent.php
Created September 19, 2023 18:55
Adds the XCD equivalent of a product's price next to the USD amount. The example is for XCD but can be used for any currency by just changing the conversion rate.
function sl_add_price_suffix( $html, $product, $price, $qty ){
if(empty($product) && !is_object($product)){
return;
}
$is_variable = $product->is_type('variable');
$min_price = '';
$max_price = '';
@UVLabs
UVLabs / Fonts
Last active February 27, 2024 02:59
A list of noteworthy fonts
Professional - Corperate
https://fonts.google.com/specimen/Inter
https://www.dafontfree.io/gilroy-font-family
https://fonts.google.com/specimen/Signika
https://fonts.google.com/specimen/DM+Sans
https://github.com/github/mona-sans
https://fonts.google.com/specimen/Albert+Sans
hhttps://fonts.google.com/specimen/Rubik?query=rubik
https://github.com/stijndevries/Eudoxus-Sans
@UVLabs
UVLabs / zoho_apis_access_token.php
Created August 31, 2023 17:41
Example PHP script for generating access token and refresh token for Zoho APIs.
<?php
$api_url = "https://accounts.zoho.com/oauth/v2/token";
$content_type = "application/x-www-form-urlencoded";
$code = "1000.7c7b9fa2259fac74331e0045d4bf24b2.7de27ed34xxxxxxxxxxxx"; //Generated with a max of 10 min life from https://api-console.zoho.com for example scope: ZohoCRM.modules.ALL
$redirect_uri = "https://example.com/zoho.php"; // When testing on Localhost with PHP local server like: php -S localhost:8080 you can set the redirect URL as the same localhost root url example: http://localhost:8080/
// Live client
// $client_id = "1000.xxx..."; //Static Client ID from https://api-console.zoho.com
@UVLabs
UVLabs / php-blacklist-checker
Created March 30, 2023 03:17
Blacklist checker script
<?php
// Simple PHP script to lookup for blacklisted IP against multiple DNSBLs at once.
// Note from Uriahs - I Didn't write any of this...I think...I'm pretty sure I just found the code somewhere online, but I can't remember..Saving as a gist for future reference.
?>
<html>
<head>
<title>DNSBL Lookup Tool - IP Blacklist Check Script</title>
</head>
<body>
@UVLabs
UVLabs / make-script-module.php
Last active January 23, 2023 13:40
Turns a WordPress JavaScript file into a module while still supporting wp_add_inline_script()
<?php
// Below function will ensure that any scripts added using wp_add_inline_script() are not touched during the filtering process.
// We need to do this because the filte runs after the inline scripts have been concatenated: https://github.com/WordPress/WordPress/blob/6.1.1/wp-includes/class-wp-scripts.php#L406
function make_scripts_modules( $tag, $handle, $src ) {
if ( 'your-script-handle' !== $handle ) {
return $tag;
}
@UVLabs
UVLabs / timezones.php
Created December 15, 2022 19:04 — forked from kulbakin/timezones.php
Array of timezones where keys are PHP timezone names and values are human friendly timezone titles.
<?php
/**
* List of timezones
*/
return array(
'Pacific/Midway' => '(UTC-11:00) Midway',
'Pacific/Niue' => '(UTC-11:00) Niue',
'Pacific/Pago_Pago' => '(UTC-11:00) Pago Pago',
'America/Adak' => '(UTC-10:00) Adak',
'Pacific/Honolulu' => '(UTC-10:00) Honolulu',
@UVLabs
UVLabs / wc-set-payment-gateway-currency.php
Last active November 20, 2021 23:36
Alter the amount sent to the payment gateway based on custom currency conversions
<?php
/*
Plugin Name: Site Specific- Set Payment Gateway Currency
Plugin URI: https://uriahsvictor.com
Description: Send the USD equivalent of an XCD amount to payment gateway for processing.
Version: 1.0.0
Author: Uriahs Victor
Author URI: https://uriahsvictor.com
Requires PHP: 7.2
License: GPLv2
@UVLabs
UVLabs / 01_github-action-create-release-on-merge.md
Last active March 30, 2024 14:48
Github Action: Create Tag and Release when a pull request is merged into master/main branch with release notes parsed from merge comment

This Github Action workflow along with the rest of these files/scripts will allow you to create a Tag as well as a Release with the release notes set to the text added in the body of the merge comment when a pull request is merged.

Create release on merge github action

Note:

Merge comment title needs to contain the text "release" or else the workflow will not run (see line 11 of create-release.yml).

@UVLabs
UVLabs / get_days_since.php
Last active February 18, 2021 21:17
Get the number of days since a specific date or timestamp in PHP with timezone support.
<?php
$date_in_the_past = '@1613681176'; // If using timestamps be sure to include '@' symbol
$date_in_the_past_obj = new DateTime($date_in_the_past);
// If timezones matter for your usecase, then use below instead. Ref: https://www.php.net/manual/en/timezones.php
// $date_to_check = '2021-02-18';
// $date_to_check_obj = new DateTime($date_to_check, new DateTimeZone('America/St_Lucia'));
// You can add a different date that you want to compare instead of "today"