Skip to content

Instantly share code, notes, and snippets.

View jonnymaceachern's full-sized avatar

Jonny jonnymaceachern

  • Developer @ Media Mechanics
  • Halifax, NS
  • 19:35 (UTC -03:00)
View GitHub Profile
@jonnymaceachern
jonnymaceachern / list.twig
Created February 18, 2020 19:32
Twig macro for converting list to sentence-like string (e.g. ["apples", "bananas, "carrots] becomes "apples, bananas, and carrots")
{# Loop through all items in a list, comma-separate them, but use "and" before the last item
e.g. ["apples", "bananas, "carrots] becomes "apples, bananas, and carrots" #}
{% macro to_sentence(items) %}
{% for item in items %}
{# First item #}
{% if loop.first %}
<span>{{ item }}{% if items|length > 2 %},{% endif %}</span>
{% else %}
@jonnymaceachern
jonnymaceachern / php.json
Last active February 14, 2020 02:43
VS Code php snippets
{
"Dump variable": {
"prefix": "pr",
"body": [
"echo '<pre>';",
"print_r($1);",
"echo '</pre>';"
]
}
}
@jonnymaceachern
jonnymaceachern / scss.json
Created January 21, 2020 19:44
VS Code snippets for SCSS files
{
"@include media-breakpoint-only(xs)": {
"description": "Bootstrap media query for 'xs' only",
"prefix": "=xs",
"body": [
"@include media-breakpoint-only(xs) {",
"\t$1",
"}"
]
},
@jonnymaceachern
jonnymaceachern / batch-convert-mp4-webm.sh
Created August 28, 2019 14:59
Batch convert mp4 to webm using ffmpeg
for i in *.mp4;
do name=`echo "$i" | cut -d'.' -f1`
echo "$name"
ffmpeg -i "$i" -acodec libvorbis -aq 5 -ac 2 -qmax 25 -threads 2 "${name}.webm"
done
@jonnymaceachern
jonnymaceachern / _show-bootstrap-breakpoints.scss
Last active April 8, 2023 11:17
Always display current breakpoint using Bootstrap 4's media breakpoint SCSS variables
body {
&:after {
content: "< #{map-get($grid-breakpoints, sm)} (xs)";
position: fixed;
z-index: 99999;
padding: 2px 15px;
bottom: 0;
left: 0;
border-top-right-radius: 5px;
background: blue;
.gitignore file
To see the file in folder make 'ls a', to modify do 'vi .gitignore file'. Use this file to insert there full pathes and names of folders/files/objects you would not want to commit to the repo.
git init
To create a new, empty repository in the current directory
git status
Shows status of current repo
git log
/* text */
'my-field-1' => array(
'type' => 'text',
'label' => __( 'Text Field 1', 'fl-builder' ),
),
/* textarea */
'my_textarea_field' => array(
'type' => 'textarea',
@SteveRyan-ASU
SteveRyan-ASU / redirect-from-json.php
Created January 31, 2018 17:14
Pantheon: Redirect via JSON feed in private file section
// PHP snippet included in wp-config.php (or settings.php).
// Including from that location in a separate file is OK as well.
<?php
// Remove any leading "www." from the host name.
$redirect_host = str_replace('www.', '', $_SERVER['HTTP_HOST']);
$redirect_path = strtolower(rtrim($_SERVER['REQUEST_URI']));
if (strlen($redirect_path) > 2) {
$redirect_path = rtrim($redirect_path, '/');
}
@webdevsuperfast
webdevsuperfast / vc_custom_icon_set.php
Created November 12, 2017 06:10 — forked from zecka/vc_custom_icon_set.php
Add a custom icon set from icomoon to visual composer vc_icon shortcode
<?php
// Add new custom font to Font Family selection in icon box module
function zeckart_add_new_icon_set_to_iconbox( ) {
$param = WPBMap::getParam( 'vc_icon', 'type' );
$param['value'][__( 'IcoMoon', 'total' )] = 'icomoon';
vc_update_shortcode_param( 'vc_icon', $param );
}
add_filter( 'init', 'zeckart_add_new_icon_set_to_iconbox', 40 );
@AustinGil
AustinGil / functions.php
Last active January 23, 2020 10:32
Only load scripts and styles if a specific shortcode is present in the content when the page/post is saved
/*
* This first function maps shortcodes to their respective resources,
* then checks whether those shortcodes exist in the content,
* then stores the required resource handles in a custom field.
* This way, we aren't running resource-intensive functions on every page load.
*/
function check_post_shortcodes($post_id) {
// Map conditional shortcodes to their respective resource handle
// Remember to manually dequeue resource handles below as well.