Skip to content

Instantly share code, notes, and snippets.

View ChrisButterworth's full-sized avatar

Chris Butterworth ChrisButterworth

View GitHub Profile
export function OneByte(bytes: number, green: boolean): number {
const CO2_PER_KWH_IN_DC_GREY = 519;
const CO2_PER_KWH_NETWORK_GREY = 475;
const CO2_PER_KWH_IN_DC_GREEN = 50;
const KWH_PER_BYTE_IN_DC = 7.2e-11;
const FIXED_NETWORK_WIRED = 4.29e-10;
const FIXED_NETWORK_WIFI = 1.52e-10;
const FOUR_G_MOBILE = 8.84e-10;
@ChrisButterworth
ChrisButterworth / Index.php
Last active November 11, 2022 12:10
Lazy html only YouTube embed
<?php
function youtube_embed($id = null) {
// Return if id isn't set
if (!$id)
return;
// Get title - seems overkill
$title = explode('</title>', explode('<title>', file_get_contents("https://www.youtube.com/watch?v=".$id))[1])[0];
@ChrisButterworth
ChrisButterworth / _mixin.scss
Created April 2, 2019 10:33
Interpolation mixin
// ----
// Sass (v3.4.21)
// Compass (v1.0.3)
// ----
// Interpolate v1.0
// This mixin generates CSS for interpolation of length properties.
// It has 5 required values, including the target property, initial
// screen size, initial value, final screen size and final value.
@ChrisButterworth
ChrisButterworth / converter.php
Created September 5, 2018 12:26
Webp converter for WordPress
<?php
namespace Converter;
use WebPConvert\WebPConvert;
class Converter
{
public $lazy = false;
public function __construct($lazy = false)
@ChrisButterworth
ChrisButterworth / functions.php
Last active December 30, 2020 12:41
Webp converter for WordPress
<?php
// Only dependency that's used
// TODO: Implement filter for the_content();
use WebPConvert\WebPConvert;
add_filter('wp_generate_attachment_metadata', function($meta) {
$path = wp_upload_dir(); // get upload directory
@ChrisButterworth
ChrisButterworth / php.ini
Created June 22, 2018 16:14
OPCache simple set up
opcache.memory_consumption=256
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=10000
opcache.max_wasted_percentage=15
opcache.revalidate_freq=0
opcache.force_restart_timeout=300
@ChrisButterworth
ChrisButterworth / merge.php
Created June 22, 2018 16:08
Merge script files
<?php
add_action( 'wp_enqueue_scripts', 'merge_all_scripts', 9999 );
function merge_all_scripts()
{
global $wp_scripts;
/*
#1. Reorder the handles based on its dependency,
The result will be saved in the to_do property ($wp_scripts->to_do)
*/
@ChrisButterworth
ChrisButterworth / readme.md
Created May 24, 2018 10:30
Making Google Analytics behave better

Making GA behave better

Part of GDPR means respecting a users right to privacy (which should be respected anyway regardless of any, this includes the right not to be tracked.

After looking this up I'm surprised at the amount of tracking services in the public domain that completely ignore this; including social media tracking and advertisers. Monsanto (Piwik) is one of the only services I've found to respect do not track requests and even gives you the tools to enable a user to disable tracking.

I've used sessionStorage in the example above but that can be switched out to use localStorage or cookies; if using cookies this needs to be explained within your privacy policy or terms and conditions.

The conditional statement can be used around every tracking function regardless of service.

@ChrisButterworth
ChrisButterworth / retreive.py
Created March 24, 2017 10:18
MailGun message download
# This Python file uses the following encoding: utf-8
"""View a message using it’s Mailgun storage key."""
import os
import sys
import uuid
import requests
def r_string(string_length=10):
"""Returns a random string of length string_length."""
@ChrisButterworth
ChrisButterworth / 0_reuse_code.js
Created June 8, 2014 15:21
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console