Skip to content

Instantly share code, notes, and snippets.

View Lewiscowles1986's full-sized avatar
🤓

Lewis Cowles Lewiscowles1986

🤓
View GitHub Profile
@BrocksiNet
BrocksiNet / shareButton.js
Created December 5, 2024 08:50
shareButton with Web Share API
document.addEventListener('DOMContentLoaded', () => {
const entryElement = document.querySelector('.entry');
if (navigator.canShare && entryElement) {
const shareButton = document.createElement('button');
shareButton.textContent = 'Share this article';
shareButton.onclick = async () => {
try {
await navigator.share({
url: location.href,
title: document.title
@marcosci
marcosci / render_universe.R
Created December 8, 2021 07:54
Rayrender Universe
library(rayrender)
library(glue)
y_dist = 8
circle <- function(x = 0, y = 0 + 20, rad = 1, nvert = 500, ...){
rads <- seq(0,2*pi,length.out = nvert)
xcoords <- cos(rads) * rad + x
ycoords <- sin(rads) * rad + y
cbind(x = xcoords, y = y_dist, z = ycoords)
@ciaranmcnulty
ciaranmcnulty / notes.md
Last active March 25, 2024 06:36
Notes on using Docker on ARM Macs (November 2021)

Docker for Mac

On M1 machines, Docker for Mac is running a lightweight linux ARM VM, then running containers within that, so containers are essentially running natively. Don't be fooled by the fact the UI or binary CLI tools (e.g. docker) might require Rosetta.

Within that VM is an emulation layer called QEmu. This can be used by docker to run Intel containers. This does not use Rosetta at all, and has a roughly 5-6X performance penalty. (If you just upgraded your CPU this may result in a similar performance to your old machine!)

Pulling and running with Docker

Many images in public registries are multi-architecture. For instance at the time of writing on Docker Hub the php:8.0-cli image has the following digests:

@dianewallace
dianewallace / woo-no-shipping-available-message.php
Last active November 17, 2020 17:42
Update the Woocommerce No Shipping message to include contact details.
add_filter( 'woocommerce_cart_no_shipping_available_html', 'myplugin_no_shipping_available_message' );
add_filter( 'woocommerce_no_shipping_available_html', 'myplugin_no_shipping_available_message' );
/**
* Update the Woocommerce No Shipping message to include contact details.
*/
function myplugin_no_shipping_available_message( $message ) {
$country = WC()->customer->get_shipping_country();
$mailto = 'mailto:' . get_option( 'admin_email' ); // Could also be 'woocommerce_stock_email_recipient'.
$link = sprintf( wp_kses( __( '<a href="%s">contact us</a>', 'my-plugin' ), array( 'a' => array( 'href' => array() ) ) ), esc_url( $mailto ) );
/* So how does this work?
I'm using ANSI escape sequences to control the behavior of the terminal while
cat is outputting the text. I deliberately place these control sequences inside
comments so the C++ compiler doesn't try to treat them as code.*/
//
/*The commands in the fake code comment move the cursor to the left edge and
clear out the line, allowing the fake code to take the place of the real code.
And this explanation uses similar commands to wipe itself out too. */
//
#include <cstdio>
@Savelenko
Savelenko / GADTMotivation.fs
Last active June 4, 2024 14:40
Motivated simulation of GADTs in F#, quite motivational
module GADTMotivation
(*
Here is a simple motivational example for GADTs and their usefulness for library design and domain modeling. Suppose we
need to work with settings which can be displayed and adjusted in a GUI. The set of possible setting "types" is fixed
and known in advance: integers, strings and booleans (check-boxes).
The GUI should show an example value for each possible setting type, e.g. 1337 for an integer setting and "Hello" for a
string setting. How can we model this small domain of setting types and computing example values?
*)
@kafran
kafran / extract_har.py
Last active November 3, 2023 20:04
Python 3 script to extract images from HTTP Archive (HAR) files
import json
import base64
import os
# make sure the output directory exists before running!
folder = os.path.join(os.getcwd(), "imgs")
with open("scr.har", "r") as f:
har = json.loads(f.read())
@AlexNDRmac
AlexNDRmac / phpenv-install.md
Last active February 13, 2024 04:17 — forked from sergeyklay/phpenv-install.md
Multiple PHP versions using phpenv and php-build

Multiple PHP versions using phpenv and php-build

Install dependecies

Debian/Ubuntu users

sudo apt install \
  autoconf \
 bison \
#!/bin/bash
# program-specific xbindkeys bindings
# there's a tool called `autokey`, which does this, but unlike xbindkeys, it doesn't catch mouse buttons
# doesn't interfere with main xbindkeys
# `pacman -S xbindkeys xdotool`
# `sleep 3 && cat /proc/$(xdotool getwindowpid $(xdotool getwindowfocus))/comm`
@freekmurze
freekmurze / bookmarklet
Last active February 22, 2019 10:13
Oh Dear! Reachable bookmarklet
javascript:{window.location='https://ohdear.app/tools/reachable?prefill='+encodeURIComponent(window.location.href)}