Skip to content

Instantly share code, notes, and snippets.

<?php
/*
*
* Every snippet can be used by placing it in your theme's functions.php file
* Everything here is made specifically for https://codecanyon.net/item/shipping-rate-by-distance-for-woocommerce/21671361/comments
*
*/
// Use this snippet in case the totals are not being automatically updated on your cart page.
@bomsn
bomsn / vultr_low_balance_alerts.sh
Created December 2, 2023 21:21
Get notified when your Vultr balance get low.
#!/bin/bash
###################################################################################################
# For instructions, see here:
# https://alikhallad.com/how-to-setup-automated-low-balance-notifications-for-your-vultr-account/
###################################################################################################
# Load the API key from the environment file
source "$(dirname "$0")/.env"
@bomsn
bomsn / hardening_startup_script.sh
Created October 29, 2023 17:12
A startup script for basic server hardening
#!/bin/bash
# Note: make sure to replace `your-sudo-user` with your username across the script
# Update system
apt-get update -y
apt-get upgrade -y
# Create a new sudo user
useradd -m -s /bin/bash your-sudo-user
@bomsn
bomsn / automatewoo_export_snippet.php
Created July 30, 2022 11:32
Export AutomateWoo plugin optin emails ( for WordPress - WooCommerce )
<?php
header('Content-type: text/csv');
header('Content-Disposition: attachment; filename="optins-data-' . date("d/m/Y") . '.csv"');
header('Pragma: no-cache');
header('Expires: 0');
$file = fopen('php://output', 'w');
fputcsv($file, array('Name', 'Email'));
$query = new AutomateWoo\Customer_Query();
@bomsn
bomsn / highlight-active-links-on-scroll.html
Created February 11, 2021 16:06
Highlight active links for one-page navigation
@bomsn
bomsn / geolocation.js
Last active March 11, 2024 16:22
Get User Postal Code ( Zip Code ) with Browser Geolocation & Google API
// jQuery must be loaded before calling this function ( for AJAX )
let getUserPostcode = () => {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(
(position) => {
let lat = position.coords.latitude,
long = position.coords.longitude,
url = "https://maps.googleapis.com/maps/api/geocode/json?latlng=" + lat + "," + long + "&key=YOUR_GOOGLE_API_KEY";
$.ajax({
type: "GET",
@bomsn
bomsn / cronjob_automation.sh
Created January 21, 2021 18:55
Sample code for cron job automation ( Create a certbot auto-renewal cron job )
#!/bin/bash
# If our cron job already exists, bail out.
if ! crontab -l &> /dev/null | grep -q "/usr/bin/certbot renew"; then
# Copy the existing cron jobs into a temporary file
crontab -l &> /dev/null > cronjobs.txt
# Add our new cron job to the file
echo "15 3 * * * /usr/bin/certbot renew --quiet" >> cronjobs.txt
# Replace content of current user crontab with the content from our cron jobs file
cat cronjobs.txt > /var/spool/cron/crontabs/"$USER"