Skip to content

Instantly share code, notes, and snippets.

@erwstout
erwstout / cache-json.php
Created November 15, 2016 15:41
Write JSON file and cache it.
<?php
/**
* Write an array to a JSON file. Replace $data with your array,
* and skip JSON encoding if you already have JSON
*/
function write_data_to_file( $filename ) {
$json = file_get_contents( 'http://path.to/external-site/file.json');
$time = time();
file_put_contents( $filename, $json );
}
@GaryJones
GaryJones / functions.php
Created October 11, 2016 23:29
Genesis: Add classes to footer widget areas container, depending on the configured number of footer widget areas.
<?php
add_filter( 'genesis_footer_widget_areas', 'gmj_add_footer_widgets_classes', 10, 2 );
/**
* Add classes to footer widget areas container, depending on the configured number of footer widget areas.
*
* @param string $output Existing footer widget areas container markup.
* @param int $footer_widgets Number of configured footer widget areas.
* @return string Possibly amended markup for footer widget areas container.
*/
@getive
getive / checksslcontext.php
Created April 14, 2016 08:43 — forked from padraic/checksslcontext.php
Correct SSL/TLS Context Settings for file_get_contents() and other PHP stream calls under PHP 5.5 (or earlier)
<?php
ini_set('display_errors', 1);
/**
* This script check how PHP makes HTTPS (SSL/TLS) requests using PHP Streams
* or cURL. Configuration options are passed as GET parameters, for example:
* http://localhost/checksslcontext.php?reconfigure=1
*
* Configuration:
* http://localhost/checksslcontext.php
* Basic PHP Streams using file_get_contents(). Default settings.
@niksumeiko
niksumeiko / disable-html-form-input-autocomplete-autofill.md
Last active November 26, 2025 15:46
Disable HTML form input autocomplete and autofill

Disable HTML Form Input Autocomplete and Autofill

  1. Add autocomplete="off" onto <form> element;
  2. Add hidden <input> with autocomplete="false" as a first children element of the form.
<form autocomplete="off" method="post" action="">
    <input autocomplete="false" name="hidden" type="text" style="display:none;">
    ...
@gterrill
gterrill / bundled.v4.js.liquid
Last active December 9, 2016 09:43
Javascript for showing bundled products as sold out if any component products are sold out
<script>
/*
Script to limit quantity for bundled products.
Instructions: http://support.shopifyconcierge.com/entries/20754371-Synchronizing-Product-Bundle-Inventory
*/
bundles = [];
{% for variant in product.variants %}{% if variant.metafields.sva.bundled %}
bundles['{{ variant.id }}'] = jQuery.parseJSON('{{ variant.metafields.sva.bundled }}');
{% endif %}{% endfor %}
@apkoponen
apkoponen / the_attachment_image_responsive_bg_style
Last active November 1, 2017 08:32
Output a style tag with responsive background image sizes (for WordPress 4.4 and up).
/**
* Output a style tag with responsive background image sizes.
*
* Example:
*
* the_attachment_image_responsive_bg_style(132, "#section-top", 40)
*
* For attachment ID 132, for an element with id="section-top" and a page
* with 20px padding on both sides of the element.
*
@gavinballard
gavinballard / best_sellers.rb
Created November 10, 2015 15:55
"Best Sellers" script example for Mastering Shopify Apps
#!/bin/ruby
require 'shopify_api'
# This is an example script for the course "Mastering Shopify Apps"
# available at http://gavinballard.com/msa/. You're free to use and
# modify this script as desired.
# Define authentication parameters. You should update these with the
# authentication details for your own shop and private application.
SHOPIFY_SHOP='mastering-apps.myshopify.com'
@djm
djm / chunk.js
Created August 19, 2015 19:49
Javascript: chunk an ES6 Map into an Array of similar sized Maps
export function chunkMap (map, chunkSize) {
const chunkedMaps = []
const mapAsArray = Array.from(map)
for (var i = 0; i < map.size; i += chunkSize) {
let chunked = mapAsArray.slice(i, i + chunkSize)
chunkedMaps.push(new Map(chunked))
}
return chunkedMaps
}
@chrisblakley
chrisblakley / server-side-ga-events.php
Last active September 18, 2024 13:10
PHP functions to send data to Google Analytics
//Parse the GA Cookie
function gaParseCookie() {
if (isset($_COOKIE['_ga'])) {
list($version, $domainDepth, $cid1, $cid2) = explode('.', $_COOKIE["_ga"], 4);
$contents = array('version' => $version, 'domainDepth' => $domainDepth, 'cid' => $cid1 . '.' . $cid2);
$cid = $contents['cid'];
} else {
$cid = gaGenerateUUID();
}
return $cid;
@neilgee
neilgee / microdata-cpt.php
Created February 4, 2015 07:35
Genesis Microdata Example - Changing a CPT SChema
add_action( 'get_header', 'themeprefix_cpt_microdata' );
//Change microdata for events custom post type
function themeprefix_cpt_microdata() {
if ('event' == get_post_type()) {//change to your cpt
//add in the microdata changes
add_filter( 'genesis_attr_entry', 'themeprefix_genesis_attributes_entry', 20 );