Skip to content

Instantly share code, notes, and snippets.

View gecugamo's full-sized avatar

Gary Cuga-Moylan gecugamo

View GitHub Profile
@gecugamo
gecugamo / unique.js
Last active February 13, 2020 15:42
JS Unique with Recursion (es6)
// unique.js
const unique = (array, newArray = [], index = 0) => {
if (index === array.length) return newArray;
if (!newArray.includes(array[index])) newArray.push(array[index]);
index += 1;
return unique(array, newArray, index);
}
export default unique;
@gecugamo
gecugamo / unique.js
Last active February 13, 2020 15:31
JS Unique with Recursion (es5)
function unique(array, newArray, index) {
if (index === array.length) return newArray;
if (newArray.indexOf(array[index]) === -1) newArray.push(array[index]);
index += 1;
return unique(array, newArray, index);
}
// unique([1, 2, 2, 3, 4, 5, 5], [], 0);
// [1, 2, 3, 4, 5]
@gecugamo
gecugamo / social-share.php
Last active March 20, 2017 19:55
WordPress Social Share
<?php
$site_url = urlencode( get_home_url() );
$post_title = urlencode( get_the_title() );
$post_url = urlencode( get_the_permalink() );
$featured_image = get_img( get_post_thumbnail_id() );
$placeholder_image = 'http://placehold.it/640x480';
$featured_image_src = has_post_thumbnail() ? $featured_image['src'] : $placeholder_image;
function get_img( $attachment_id, $attachment_size = 'full' ) {
@gecugamo
gecugamo / wp-config-sample.php
Created February 7, 2017 22:22
WordPress wp-config-sample.php
<?php
/**
* The base configuration for WordPress
*
* The wp-config.php creation script uses this file during the
* installation. You don't have to use the web site, you can
* copy this file to "wp-config.php" and fill in the values.
*
* This file contains the following configurations:
*
@gecugamo
gecugamo / breadcrumbs.php
Created February 7, 2017 22:20
WordPress Breadcrumbs
<?php
if ( ! function_exists( 'breadcrumbs' ) ) :
function breadcrumbs() {
echo '<ul class="breadcrumbs">';
if ( ! is_home() ) {
echo '<li><a href="' . esc_url( get_option( 'home' ) ) . '">Home</a></li>';
}
if ( is_category() ) {
@gecugamo
gecugamo / pagination.php
Created February 7, 2017 22:20
WordPress Pagination
<?php
if ( ! function_exists( 'pagination' ) ) :
function pagination($pages = '') {
global $paged;
if(empty($paged)) $paged = 1;
if($pages == '')
@gecugamo
gecugamo / wp-content.gitignore
Created December 7, 2015 16:52
wp-content.gitignore
*.log
advanced-cache.php
backup-db/
backups/
blogs.dir/
cache/
upgrade/
uploads/
wp-cache-config.php
@gecugamo
gecugamo / pre-get-posts.php
Created December 3, 2015 17:47
Pre Get Posts Filter
<?php
function pgp_filter( $query ) {
if ( $query->is_main_query() && !is_admin() ) {
$query->set( $key, $value );
}
}
add_action( 'pre_get_posts', 'pgp_filter' );
@gecugamo
gecugamo / gform_grid.css
Last active December 2, 2015 22:04
CSS to allow use of Bootstrap grid with Gravity Forms
.gform_fields {
list-style-type: none;
margin-right: -15px;
margin-left: -15px;
padding: 0;
}
.gfield {
margin-bottom: 15px;
padding-right: 15px;
<?php
// Add product to request list
function add_product_id($product_id) {
$product_ids = get_product_ids();
// If product id is in array, return
if (in_array($product_id, $product_ids)) {
return;
}