Skip to content

Instantly share code, notes, and snippets.

@zlove
zlove / pyenv-cheatsheet.sh
Last active March 27, 2018 19:24
pyenv and pyenv virtualenv cheatsheet. This is not at all comprehensive - just a reminder for common tasks.
# Show locally installed Python versions. With pyenv virtualenv installed this
# also lists local virtualenvs
pyenv versions
# List Python versions which are available to install
pyenv install --list
# Install Python version 2.7.14. See `pyenv install --list` for available <versions>
pyenv install <version>
# E.g.
@zlove
zlove / image64.sh
Last active September 27, 2017 00:16 — forked from kamikat/image64.sh
Create data URI image from Terminal command
#! /usr/bin/env bash
# Examples:
# ./image64.sh myImage.png
# outputs: data:image/png;base64,xxxxx
# ./image64.sh myImage.png -img
# outputs: <img src="data:image/png;base64,xxxxx">
function usage {
echo "usage: $0 <image_filename> [--img]"
@zlove
zlove / fix_srcset_urls.php
Last active April 9, 2016 06:36
Fix srcset URLs at WP Engine
<?php
/**
* Change srcset URLs to https if the page is loaded via https
* Activate with:
*
* add_filter( 'wp_calculate_image_srcset', 'zbs_fix_srcset_for_https' );
*
* @param array $sources array of sources used in srcset.
* @return array
*/
@zlove
zlove / mmenu-wp-open-submenu.js
Last active November 17, 2015 19:15
jQuery to allow Wordpress menu items to open sub-menus directly using mmenu
/*
mmenu (http://mmenu.frebsite.nl/) has a way to make a click on a menu item
open a sub-menu (as opposed to a click on the arrow to the right of the item).
See:
http://mmenu.frebsite.nl/support/tips-and-tricks.html#tt-subopenlinks
https://github.com/BeSite/jQuery.mmenu/issues/45
However, Wordpress menus by default do not allow an easy way
to use either of these techniques. This snippet modifies
@zlove
zlove / gist:3b9b6a611715ec3a8a60
Last active February 25, 2020 22:53
Preview WooCommerce Emails
<?php
/**
* Quick hack to preview WooCommerce e-mails.
* Based on drrobotnik's answer from Stack Overflow: http://stackoverflow.com/a/27072101/186136
*
* Add this to <yourtheme>/functions.php and then visit a url like:
* http://<site_url>/wp-admin/admin-ajax.php?action=previewemail
*
* @return null
*/
@zlove
zlove / gist:51c3db742aef49218083
Created May 22, 2015 07:01
Order WooCommerce products by Title, ignoring a leading "The"
add_filter('posts_orderby', 'zbyte_edit_posts_orderby');
function zbyte_edit_posts_orderby($orderby_statement) {
global $wp_query;
$is_product_list =
is_shop() ||
is_product_category() ||
is_product_tag();
@zlove
zlove / jquery.bxslider-alt.js
Last active January 24, 2018 19:58
Wrap bxSlider so that we can override options per slider with data attributes.
;(function ($) {
/**
* Return an object consisting of properties of 'data'
* that match the regex 'pattern'. If trim is not false,
* trim the matched 'pattern' from the property name,
* and make the first char of the remaining property
* name lowercase.
*/
function filterData(data, pattern, trim) {
var data,
@zlove
zlove / crontab
Last active July 6, 2021 05:22
Crontab entry to clean up the Magento sessions directory. Edit php.ini and change session.gc_maxlifetime to adjust how long session data is kept around. From http://stackoverflow.com/a/9631312/186136
0 2 * * * /usr/bin/find /FIXME/PATH/TO/DOMAIN.COM/var/session -mindepth 1 -maxdepth 1 -type f -cmin +$(/usr/lib/php5/maxlifetime) -print0 -exec rm {} \; >/dev/null 2>&1