Skip to content

Instantly share code, notes, and snippets.

@lewiswalsh
lewiswalsh / sleep.js
Last active May 27, 2022 19:12
Javascript Sleep function #js
function sleep (time) {
return new Promise((resolve) => setTimeout(resolve, time));
}
sleep(500).then(() => {
// Do something after the sleep!
})
@lewiswalsh
lewiswalsh / emptyanchor.css
Last active May 27, 2022 19:11
Display links when the <a> has no text value but the href attribute has a link #css
a[href^="http"]:empty::before {
content: attr(href);
}
@lewiswalsh
lewiswalsh / home-raise-z.gcode
Last active May 27, 2022 19:07
GCode to raise extruder before heating #gcode #3dprinting #cnc
G28 Z ; Home Z - LW
G0 Z50 ; Move Z to 50 - LW
@lewiswalsh
lewiswalsh / pi-camera-settings
Last active May 27, 2022 19:07
Octoprint mjpg-streamer Raspberry Pi camera settings #raspberrypi
camera_raspi_options="-x 1440 -y 1080 -fps 15 -quality 95 -sh 25 -br 60 -co 40 -sa 10 -awb fluorescent"
@lewiswalsh
lewiswalsh / dodyndns.sh
Last active May 27, 2022 19:06
Update DigitalOcean domain record from bash #bash
#!/bin/bash
# Use CRON to regularly update for DIY DynDNS
PUBLIC_IPV4=$(curl ifconfig.co)
API_ACCESS_TOKEN=<your_access_token>
RECORD_ID=<your_record_id>
curl -X PUT -H "Content-Type: application/json" -H "Authorization: Bearer ${API_ACCESS_TOKEN}" -d '{"data":"'"${PUBLIC_IPV4}"'"}' "https://api.digitalocean.com/v2/domains/centralindustrial.co.uk/records/${RECORD_ID}"
@lewiswalsh
lewiswalsh / woocommerce_on_update.php
Last active May 27, 2022 19:06
Do something when a woocommerce product is updated #php #wordpress
<?php
add_action( 'added_post_meta', 'mp_sync_on_product_save', 10, 4 );
add_action( 'updated_post_meta', 'mp_sync_on_product_save', 10, 4 );
function mp_sync_on_product_save( $meta_id, $post_id, $meta_key, $meta_value ) {
if ( $meta_key == '_edit_lock' ) { // we've been editing the post
if ( get_post_type( $post_id ) == 'product' ) { // we've been editing a product
$product = wc_get_product( $post_id );
// do something with this product
}
}
@lewiswalsh
lewiswalsh / windows-terminal-colours.json
Last active May 27, 2022 19:00
Amber, Green,and monochrome Blue (think WarGames) colour schemes for Windows Terminal
// Enable "experimental.retroTerminalEffect" and crank up the "fontSize"
// For that true WarGames look set "cursorShape" to "filledBox" and install this typeface:
// https://fontstruct.com/fontstructions/show/789830/wargames_2
{
"name" : "LW Amber CRT",
"foreground" : "#FFB000",
"background" : "#282828",
"cursorColor" : "#FFB000",
"black" : "#FFB000",
@lewiswalsh
lewiswalsh / submit-form.html
Last active May 27, 2022 18:57
Submit a form with a button outside the form #html
<form id="my-form">
<label for="name">Name:</label>
<input type="text" name="name"></input>
</form>
<button type="submit" form="my-form">Submit</button>
@lewiswalsh
lewiswalsh / unsplash.url
Last active May 27, 2022 18:57
Get a random image from Unsplash and set size #html
http://source.unsplash.com/random/1200x600
@lewiswalsh
lewiswalsh / certer-horizontally-and-vertically.css
Last active May 27, 2022 18:52
Center horizontally and vertically in CSS #css
display: grid;
place-items: center;