Skip to content

Instantly share code, notes, and snippets.

View leepeterson's full-sized avatar
:octocat:

Lee Peterson leepeterson

:octocat:
View GitHub Profile

Algorithmic layouts

You are looking at the most important, and most abundant thing on the web. You can't see it, unfortunately, because it's very small… aaaaand it's invisible — so having a magnifying glass doesn't really help here. But still.

I'm talking, of course, about U+0020; not to be confused with the band U2, who are just as ubiquitous, but far less useful.

This unicode point, representing the humble space character, is between every word, in every run of text, on every page of the web. And it has a very special characteristic: it's not sticky like glue. If two words are neighbors but there's not enough room for both of them, the space will free the second word to wrap around and start a new line.

Before getting into flexible containers, viewport meta tags, and @media breakpoints this humble character is what makes the web fundamentally 'responsive'. That is: able to change the layout of its content to suit different devices, contexts, and settings. Browser text does this automa

@tavinus
tavinus / simpleColors.sh
Last active December 6, 2023 23:55
"universal" terminal colors
#!/bin/sh
# Gustavo Arnosti Neves - Dec 2018
# Modified from many other snippets
# Adapted to work virtually anywhere
# Works on busybox/ash
# This script: https://gist.github.com/tavinus/925c7c9e67b5ba20ae38637fd0e06b07
# SO reference: https://stackoverflow.com/questions/16843382/colored-shell-script-output-library
@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
@chrismccoy
chrismccoy / gutenberg.txt
Last active April 4, 2024 20:34
Gutenberg Resources
How to parse Gutenberg content for headless WordPress
https://kinsta.com/blog/headless-wordpress-gutenberg/
Adding wrapper to Gutenberg’s Table block
https://helloadmin.com/adding-wrapper-to-gutenbergs-table-block/
Display specific Gutenberg blocks of a post outside of the post content in the theme
https://florianbrinkmann.com/en/display-specific-gutenberg-blocks-of-a-post-outside-of-the-post-content-in-the-theme-5620/
Modifying the Markup of a Core Block
<?php
namespace Foo\Blocks;
/**
* Generic block rendering callback function to load a block from a theme template part.
*
* Loads a block from the `blocks` subdirectory according to the name of the block, and places the
* block attributes and block content into namespaced query vars. If there's no corresponding block
* template part, the block content is returned unaltered.
@devinsays
devinsays / example-ajax-enqueue.php
Last active October 4, 2023 13:09
Simple WordPress Ajax Example
<?php
function example_ajax_enqueue() {
// Enqueue javascript on the frontend.
wp_enqueue_script(
'example-ajax-script',
get_template_directory_uri() . '/js/simple-ajax-example.js',
array( 'jquery' )
);
@saas786
saas786 / wp-localhost-requests.php
Created September 7, 2017 06:20
WordPress annoying issue, while working locally using http api you keep getting "A valid URL was not provided", or using functions such as "wp_safe_remote_request,wp_safe_remote_get or wp_safe_remote_post" and you are unable to request local website and you are not sure why its not working, because same code work on live.
<?php
/**
* Plugin Name: Allow localhost http requests.
* Plugin URI: https://gist.github.com/saas786/a567363477df7e28b0c1df6295cadf75/
* Description: Note: Please don't use it on live website. If you are working locally, sometimes you get errors such as "A valid URL was not provided" or such, specially when you are interacting with website which is also hosted locally, so it becomes annoying at times to find the cause, and most of the time its wp_safe_remote_request, wp_safe_remote_get or wp_safe_remote_post functions who are the culprit. So this plugin is a quick fix.
* Author: saas786
* Version: 0.1
*/
add_filter( 'http_request_host_is_external', 'wplr_http_request_host_is_external' );
function wplr_http_request_host_is_external(){
@chasecmiller
chasecmiller / plugin_debug.php
Last active September 9, 2019 23:03
Proof of concept of a WordPress mu-plugin to automatically disable plugins that start throwing errors.
<?php
/*
Plugin Name: Plugin Debugging Tool
Description: Attempt to automatically de-activate plugins that are causing errors. Doesn't always work. This must be installed in the mu-plugins directory.
Author: Chase C. Miller
Version: 1.0
Author URI: http://crumbls.com
*/
namespace Crumbls\Debug\Plugins;
absint
access_denied_splash
activate_plugin
activate_plugins
add_action
add_blog_option
add_clean_index
add_comment_meta
add_comments_page
add_cssclass
<?php
namespace gmazzap;
/**
* @param callable $looper Callback that receives post object, post index and current WP_Query.
* It is possible to use any template tags inside the callback.
* @param array $args Array of WP_Query arguments. Optional, when not provided, main query will be used.
*/
function loop(callable $looper, array $args = null) {