Skip to content

Instantly share code, notes, and snippets.

@aaronsummers
aaronsummers / cleaning git branches.md
Created July 29, 2022 14:47
Cleaning up Git Branches

Source

After working with branch per feature for a while any Git-repository becomes a mess of outdated and not finished branches.

To deal with this issue, we need to clean-up three kinds of branches:

  • Local branches – our day-to-day working branches
  • References to remote branches – aka origin/branch-name items
  • Actual remote branches – branches on remote server(e.g.: github, bitbucket, gitorius)
@aaronsummers
aaronsummers / array_flatten.php
Created June 10, 2022 12:21
Flatten Multidimentional Arrays in PHP
<?php
function array_flatten($arrays) {
if ( !is_array($arrays) )
{
return false;
}
$result = array();
foreach ( $arrays as $key => $value )
{
@aaronsummers
aaronsummers / accessibility-cache-mac.md
Created May 27, 2022 07:20
Accessibility Cache Mac
  • Open the Terminal app, found in Applications > Utilities.
  • Copy the following and press Return: sudo tccutil reset Accessibility
  • When prompted, enter your administrator password to approve the command.
  • You shouldn’t see any feedback; the command will just complete. Now immediately restart your Mac manually—don’t force restart it—from  > Restart.
  • When the macOS session is running and accepts your input, return to the Privacy tab and check any boxes needed to enable software that requires it. Some apps will prompt you after restart as they recognize they’re missing permissions.
@aaronsummers
aaronsummers / mega-menu-walker.php
Last active May 19, 2022 10:01
WordPress mege menu with featured images and alternative layout if the menu contains more than 4 items
<?php
/**
* Nav Menu API: Walker_Nav_Menu class
*
* @package WordPress
* @subpackage Nav_Menus
* @since 4.6.0
*/
/**
@aaronsummers
aaronsummers / sed.md
Created April 11, 2022 13:47
How to Use sed to Find and Replace String in Files

https://linuxize.com/post/how-to-use-sed-to-find-and-replace-string-in-files/

When working with text files, you’ll often need to find and replace strings of text in one or more files.

sed is a stream editor. It can perform basic text manipulation on files and input streams such as pipelines. With sed, you can search, find and replace, insert, and delete words and lines. It supports basic and extended regular expressions that allow you to match complex patterns.

In this article, we’ll talk about how to find and replace strings with sed. We’ll also show you how to perform a recursive search and replace.

Find and Replace String with sed #

@aaronsummers
aaronsummers / document-ready-function.js
Created December 6, 2021 11:14
Javascript Document Ready
// https://stackoverflow.com/questions/45291962/vanilla-js-version-of-jquery-document-on-click-for-links#answer-45292145
function addEvent(parent, evt, selector, handler) {
parent.addEventListener(evt, function(event) {
if (event.target.matches(selector + ', ' + selector + ' *')) {
handler.apply(event.target.closest(selector), arguments);
}
}, false);
}
/* To be used as */
@aaronsummers
aaronsummers / Adding-meta-fields-with-orderby-endpoint-to-WordPress-rest_API.php
Created December 6, 2019 13:36
Adding meta fields with orderby endpoint to WordPress rest API
<?php
// Register the meta field for the rest api
// https://stackoverflow.com/questions/56460557/how-to-include-meta-fields-in-wordpress-api-post#answer-56508996
add_action( 'rest_api_init', 'register_postviews_meta_fields');
function register_postviews_meta_fields(){
register_meta( 'post', 'wpb_post_views_count', array(
'type' => 'integer',
'description' => 'Post views',
'single' => true,
@aaronsummers
aaronsummers / filter.html
Last active October 31, 2021 06:32
Simple multiple select menu filtering a html table
<div class="filter">
<select name="year">
<option value="all">Please Select</option>
<option value="1998">1998</option>
<option value="2000">2000</option>
</select>
<select name="location">
<option value="all">Please Select</option>
<option value="london">London</option>
<option value="paris">Paris</option>
@aaronsummers
aaronsummers / multidimentional-array.php
Last active July 15, 2021 14:18
Create an array of arrays, building a multidimentional array with an array
<?php
/*
The important thing here is having 2x empty arrays.
The first array is the parent - level 1 array
The second array is the child - level 2 array
*/
$examples = array(
'item 1',
'item 2',
'item 3',