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
#include "Student.h" | |
using namespace std; | |
// This is the constructor. | |
Student::Student(string theName, double theGpa) : name(theName), gpa(-1) { | |
set_gpa(theGpa); | |
} |
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
// 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; |
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 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', |
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
# 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") }') |
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
{ | |
"$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": { |
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 | |
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!' ); | |
} | |
} |