Skip to content

Instantly share code, notes, and snippets.

@scottnelle
scottnelle / woocommerce-exclude-categories.php
Last active September 13, 2019 11:32
Exclude specific categories from being considered when WooCommerce selects related products. $exclude is an array of category names or slugs. Note that WooCommerce caches products selected by category for a day, so once you install this code you'll have to save a product to clear the cache and see the results.
<?php
/**
* Exclude specific categories from being considered when selecting related products
*/
function my_exclude_related_terms( $terms ) {
$exclude = array( 'First Category', 'second-category' );
foreach ( $terms as $i => $term ) {
if ( in_array( $term->name, $exclude ) || in_array( $term->slug, $exclude ) ) {
unset( $terms[ $i ] );
}
package isbn;
import java.util.regex.Pattern;
/**
* ISBN class.
*/
public class Isbn {
/** Number of digits in ISBN. */
public static final int LENGTH = 13;
@garnaat
garnaat / gist:5154370
Created March 13, 2013 17:35
Configure a internet-connected VPC from scratch
import boto.vpc
import time
REGION_NAME = 'us-west-2'
AMI_ID = 'ami-8e27adbe' # Amazon Linux AMI
conn = boto.vpc.connect_to_region(REGION_NAME)
# Create a VPC
vpc = conn.create_vpc('10.0.0.0/16')
@alecgorge
alecgorge / java-properties.php
Created May 18, 2011 00:29
Parse Java properties files in PHP
<?php
function parse_properties($txtProperties) {
$result = array();
$lines = split("\n", $txtProperties);
$key = "";
$isWaitingOtherLine = false;
foreach ($lines as $i => $line) {
if (empty($line) || (!$isWaitingOtherLine && strpos($line, "#") === 0))
continue;