Skip to content

Instantly share code, notes, and snippets.



View GitHub Profile
johnlewisdesign / another-close-x-pure-css.html
Created Aug 4, 2020
Creates a close button X in pure CSS
View another-close-x-pure-css.html
<span class="close-x"></span>
.close-x {
display: inline-block;
width: 20px;
height: 20px;
border: 7px solid #f56b00;
linear-gradient(45deg, rgba(0,0,0,0) 0%,rgba(0,0,0,0) 43%,#fff 45%,#fff 55%,rgba(0,0,0,0) 57%,rgba(0,0,0,0) 100%),
linear-gradient(135deg, #f56b00 0%,#f56b00 43%,#fff 45%,#fff 55%,#f56b00 57%,#f56b00 100%);
johnlewisdesign / single-element-x.css
Last active Aug 4, 2020
A close button X with a single div element
View single-element-x.css
View covid-cornwall-table.html
<td>COVID-19 DEATHS</td>
<td><a href="" rel="nofollow"><strong>ONS geography MSOA name</strong></a></td>
View yinyang-purecss.css
#yin-yang {
width: 96px;
box-sizing: content-box;
height: 48px;
background: #eee;
border-color: red;
border-style: solid;
border-width: 2px 2px 50px 2px;
border-radius: 100%;
position: relative;
johnlewisdesign /
Last active Jun 20, 2020
Install Hackint0sh-friendly Docker, avoiding MacOS hypervisor virtualisation issues. Note: may need to tweak sys prefs/authenticate
brew install docker docker-machine
brew cask install virtualbox
# below line replaced - disabling virtualisation checks
# docker-machine create --driver virtualbox default
docker-machine create -d virtualbox --virtualbox-no-vtx-check default
docker-machine env default
eval "$(docker-machine env default)"
docker run hello-world
docker-machine stop default
View rangeSlider.js
function getVals(){
// Get slider values
var parent = this.parentNode;
var slides = parent.getElementsByTagName("input");
var slide1 = parseFloat( slides[0].value );
var slide2 = parseFloat( slides[1].value );
// Neither slider will clip the other, so make sure we determine which is larger
if( slide1 > slide2 ){ var tmp = slide2; slide2 = slide1; slide1 = tmp; }
var displayElement = parent.getElementsByClassName("rangeValues")[0];
johnlewisdesign /
Created Jun 18, 2020
Overriding MySQL root in emergency

A safer way to do this would be to add the "init-file=/tmp/grant.sql" to the [mysqld] section of your my.cnf file. In /tmp/grant.sql you would have...

SET PASSWORD FOR root@localhost = PASSWORD('xxxx');

or whatever SQL that would fix the root user.

Restart MySQL and the password is reset. You can then remove /tmp/grant.sql and remove the init-file line from your configuration.

Using the skip-grant-tables exposed your entire database to anyone or any service that has access to your mysql instance. If you make sure that the grant.sql file only is readable by the mysql daemon user, you will have less exposure.

johnlewisdesign / change-shipping-class.php
Last active Jun 18, 2020
Change shipping class en masse [WordPress/WooCommerce]
View change-shipping-class.php
/** The category IDs containing the posts you want to change */
$category_ids = array(48, 50, 51, 52, 53); // array of ints or single int
/** The shipping class to set for the products */
$shipping_class_slug = "postcards"; // found in "shipping classes" in woocommerce settings
/** Run query to collect our data */
$products = new WP_Query(array(
'post_type' => 'product',
'posts_per_page' => -1,
'fields' => 'ids',
johnlewisdesign / hide-cats-from-admin.php
Last active Jun 18, 2020
Hides categories from everywhere, even admin screens [WordPress/WooCommerce]
View hide-cats-from-admin.php
* Hide Specified Categories (by ID) from administrators
add_action( 'admin_init', 'jl_do_terms_exclusion' );
function jl_do_terms_exclusion() {
if( current_user_can('administrator') ) {
add_filter( 'list_terms_exclusions', 'jl_list_terms_exclusions', 10, 2 );
johnlewisdesign / set-slug-postmeta.php
Created Jun 18, 2020
WordPress - set postmeta (slug)
View set-slug-postmeta.php
add_action('save_post', 'set_slug');
function set_slug($post_id){
$new_slug = get_post_meta($post_id,'custom-slug', true);
$post_args = array(
'ID' => $post_id,
'post_name' => $new_slug,