Skip to content

Instantly share code, notes, and snippets.

@painedpineapple
painedpineapple / auto-add-alt-text.js
Created September 9, 2015 22:30
Auto adds alt text to HTML <img> based upon the filename found in the src. jQuery required.
let fileNameFinder = /([\w\d-]+.jpg|[\w\d-]+.png)/;
let altTextFinder = /(.*)\.[^.]+$/;
$('img').each(function() {
if(!$(this).attr('alt')) {
let fileName = $(this).attr('src').match(fileNameFinder)[0];
let altText = fileName.match(altTextFinder)[1];
$(this).attr('alt', altText);
}
padding: calc(100% / (percentage of width the item takes/2) - (font size)) 0;
function cdnExternalOrLocal ($url) {
$cdnIsUp = get_transient('cdn_is_up');
$load_source;
if ($cdnIsUp) {
$load_source = 'external';
} else {
$cdn_response = wp_remote_get($url);
if( is_wp_error( $cdn_response ) || wp_remote_retrieve_response_code($cdn_response) != '200' ) {
$load_source = 'local';
}
// index.js – don't let registerServiceWorker run in WP environment
if (process.env.NODE_ENV !== 'production') {
registerServiceWorker()
}
// functions.php
@painedpineapple
painedpineapple / swatch.liquid
Created August 13, 2019 18:15
Shopify Swatches w/out selectCallback function
{% comment %}
Set the extension of your color files below. Use 'png', 'jpeg', 'jpg' or 'gif'.
{% endcomment %}
{% assign file_extension = 'png' %}
{% if swatch == blank %}
<div class="swatch error">
<p>You must include the snippet swatch.liquid with the name of a product option.</p>
<p>Use: <code>{% raw %}{% include 'swatch' with 'name of your product option here' %}{% endraw %}</code></p>
type t('a) = (. Js.t('a)) => React.element;
[@bs.module "google-maps-react"]
external _make: {. "apiKey": string} => t('a) = "GoogleApiWrapper";
let wrap = (apiKey: string, component) => {
_make({"apiKey": apiKey})(. component);
};
"""""""""""""""""""""""""""""""""""""""""""""""
"Install Plugins
"""""""""""""""""""""""""""""""""""""""""""""""
call plug#begin('~/.vim/plugged')
" Themes
" https://github.com/haishanh/night-owl.vim
Plug 'haishanh/night-owl.vim'
@painedpineapple
painedpineapple / ReFormFieldArrayExample.re
Last active November 6, 2019 02:18
ReForm Field Array Example
// https://github.com/Astrocoders/reform/blob/master/packages/demo/src/FavoriteColorsForm.re
module FavoriteColorsLenses = [%lenses
type t = {
name: string,
hex: string,
}
];
module StateLenses = [%lenses
@painedpineapple
painedpineapple / Downshift.re
Last active November 5, 2019 22:06
bs-downshift-hooks
/** Developed with "downshift": "^3.4.1" */
type highlightedIndex = int;
type isOpen = bool;
[@bs.module "downshift"] [@bs.scope "useSelect"]
external stateChangeTypes: {
.
"MenuKeyDownArrowDown": string,
"MenuKeyDownArrowUp": string,