Skip to content

Instantly share code, notes, and snippets.

/*
This svelte store is a reference to make super quick live and interactive pieces of code.
See its announcement at https://www.youtube.com/watch?v=A8jkJTWacow&t=18579s
*/
type Options<T> = {
validator: (data: T) => void;
};
export function live<T>(path: string, initialValue: T, options?: Options<T>) {
@Merott
Merott / tailwind-colors-as-css-variables.md
Last active May 23, 2024 07:44
Expose Tailwind colors as CSS custom properties (variables)

This is a simple Tailwind plugin to expose all of Tailwind's colors, including any custom ones, as custom css properties on the :root element.

There are a couple of main reasons this is helpful:

  • You can reference all of Tailwind's colors—including any custom ones you define—from handwritten CSS code.
  • You can define all of your colors within the Tailwind configuration, and access the final values programmatically, which isn't possible if you did it the other way around: referencing custom CSS variables (defined in CSS code) from your Tailwind config.

See the Tailwind Plugins for more info on plugins.

@bdaley
bdaley / wc-regenerate-and-notify.php
Last active July 28, 2021 00:02
Adds an action to the order page that allows you to regenerate download permissions AND extends the expiration date for WooCommerce downloads.
<?php
add_filter('woocommerce_order_actions', 'wc_regenerate_and_notify_custom_order_action');
function wc_regenerate_and_notify_custom_order_action( $actions ) {
// Remove the woocommerce option to regenerate to avoid confusion
unset($actions['regenerate_download_permissions']);
// Add our new action (executed below)
$actions['wc_regenerate_and_notify'] = __('Regenerate permissions & send link to customer', 'wc-regenerate-and-notify');
return $actions;
@LeaVerou
LeaVerou / dabblet.css
Last active March 28, 2024 06:22
Two column <dl> with two lines of CSS! Thank you Grid Layout!
/**
* Two column <dl> with two lines of CSS! Thank you Grid Layout!
* Limitation: Breaks if we have multiple consecutive <dt>s or <dd>s
*/
dl {
display: grid;
grid-template: auto / 10em 1fr;
}
@tameemsafi
tameemsafi / emails.php
Last active April 15, 2024 12:42
Send an email programmatically in wordpress with wp_mail using the woocommerce transaction emails template.
<?php
// Define a constant to use with html emails
define("HTML_EMAIL_HEADERS", array('Content-Type: text/html; charset=UTF-8'));
// @email - Email address of the reciever
// @subject - Subject of the email
// @heading - Heading to place inside of the woocommerce template
// @message - Body content (can be HTML)
function send_email_woocommerce_style($email, $subject, $heading, $message) {
@gskema
gskema / color-gradient.js
Last active March 2, 2024 22:14
Generate gradient color from 2 or 3 colors using JavaScript. Example: https://jsfiddle.net/e18g5f3L/
/**
* You may use this function with both 2 or 3 interval colors for your gradient.
* For example, you want to have a gradient between Bootstrap's danger-warning-success colors.
*/
function colorGradient(fadeFraction, rgbColor1, rgbColor2, rgbColor3) {
var color1 = rgbColor1;
var color2 = rgbColor2;
var fade = fadeFraction;
// Do we have 3 colors for the gradient? Need to adjust the params.
@kvermeille
kvermeille / bruteforceZip.js
Created December 28, 2015 16:01
A naive nodejs script to brute force password protected zip files, with all password that match /[a-z]+/
// zipping:
// zip -e target.zip file.something #...prompt for password
// unzipping:
// 7z e target.zip -pPASSWORD
////////////////////
function Dictionary(ab) {
this.ab = ab;
<?php
function bk_title_order_received( $title, $id ) {
if ( is_order_received_page() && get_the_ID() === $id ) {
$title = "Thank you for your order!";
}
return $title;
}
add_filter( 'the_title', 'bk_title_order_received', 10, 2 );
@shamasis
shamasis / event-layer-coordinates.js
Created June 7, 2014 20:40
Cross browser layerX and layerY in JavaScript
/**
* Get layerX and layerY of an event across all browsers without
* using the deprecated layerX of webkit.
* It stores `targetX` and `targetY` in the event, to act like `layerY`
* and `layerY` respectively.
*/
getElementPosition = (function () {
var body = window.document.body || window.document.documentElement;
return function (event) {