Skip to content

Instantly share code, notes, and snippets.

View MonteLogic's full-sized avatar
♂️

Monte Logic MonteLogic

♂️
View GitHub Profile
@MonteLogic
MonteLogic / Student.cpp
Last active April 4, 2021 19:16 — forked from drpventura/Student.cpp
Student class moved to separate .h and .cpp files. See video at https://youtu.be/gyA7uDlazkc.
#include "Student.h"
using namespace std;
// This is the constructor.
Student::Student(string theName, double theGpa) : name(theName), gpa(-1) {
set_gpa(theGpa);
}
@MonteLogic
MonteLogic / WC_checkout_field_validation
Created August 20, 2022 07:47 — forked from codehooligans/WC_checkout_field_validation
WooCommerce Checkout form DOB date field validation in jQuery
// We are using the WooCommerce Checkout Field Editor plugin in addition to WooCommerce. The Checkout Field Editor
// does a nice job at providing a UI for manage additional fields. But doesn't provide any method to do validations.
// So this code helps with that on a very specific implemention where we have a Gender select and a DoB date selector.
// On the Gender we want to ensure the selected value is 'Male' or 'Female' only. We don't want the
default option 'Choose Option' to be valid. On the DoB we want to enforce the user is 18 or older.
add_action( 'woocommerce_after_checkout_validation', 'woo_checkout_additional_field_validation' );
function woo_checkout_additional_field_validation() {
if (!defined('WOOCOMMERCE_CHECKOUT')) {
return;
@MonteLogic
MonteLogic / zip_to_state.php
Created August 22, 2022 00:38 — forked from loureirorg/zip_to_state.php
State from a zipcode (US)
<?php
function zipToState($zipcode)
{
/* 000 to 999 */
$zip_by_state = [
'--', '--', '--', '--', '--', 'NY', 'PR', 'PR', 'VI', 'PR', 'MA', 'MA', 'MA',
'MA', 'MA', 'MA', 'MA', 'MA', 'MA', 'MA', 'MA', 'MA', 'MA', 'MA', 'MA', 'MA',
'MA', 'MA', 'RI', 'RI', 'NH', 'NH', 'NH', 'NH', 'NH', 'NH', 'NH', 'NH', 'NH',
'ME', 'ME', 'ME', 'ME', 'ME', 'ME', 'ME', 'ME', 'ME', 'ME', 'ME', 'VT', 'VT',
'VT', 'VT', 'VT', 'MA', 'VT', 'VT', 'VT', 'VT', 'CT', 'CT', 'CT', 'CT', 'CT',
@MonteLogic
MonteLogic / upload_to_gist.sh
Created September 3, 2022 05:53 — forked from ryanli1994/upload_to_gist.sh
upload file to gist bash
# 0. Your file name
FNAME=worker.log
GITHUB_USERNAME=kigawas
# 1. Somehow sanitize the file content
# Remove \r (from Windows end-of-lines),
# Replace tabs by \t
# Replace " by \"
# Replace EOL by \n
CONTENT=$(sed -e 's/\r//' -e's/\t/\\t/g' -e 's/"/\\"/g' "${FNAME}" | awk '{ printf($0 "\\n") }')
@MonteLogic
MonteLogic / block.json
Last active September 16, 2022 15:52 — forked from ryanwelcher/block.json
{
"$schema": "https://schemas.wp.org/trunk/block.json",
"apiVersion": 2,
"name": "create-block/mol-custom-blocks",
"version": "0.1.0",
"title": "Monte Logic's Custom Blocks",
"category": "text",
"icon": "flag",
"description": "A Gutenberg block to show your pride! This block enables you to type text and style it with the color font Gilbert from Type with Pride.",
"attributes": {
@MonteLogic
MonteLogic / woo-blocks-check-house-number-in-shipping-address.php
Created November 2, 2022 17:42 — forked from woogists/woo-blocks-check-house-number-in-shipping-address.php
[WooCommerce Blocks] Check if the shipping address contains a house number
<?php
add_action( 'woocommerce_store_api_checkout_update_order_from_request', 'woo_blocks_address_field_validation', 10, 2);
function woo_blocks_address_field_validation( WC_Order $order, $request ) {
$shipping_address = $order->get_address('shipping')['address_1'];
if ( $shipping_address && ! preg_match( '/[0-9]+/', $shipping_address ) ) {
throw new Exception( 'Your shipping address must contain a house number!' );
}
}