This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
The below code converted the outer most array to object and not the nested arrays. | |
$object = json_decode(json_encode($array), false); | |
but this will force all sub elements to objects | |
$object = json_decode(json_encode($array, JSON_FORCE_OBJECT), false); | |
I'm pretty sure the solution would be similar when converting from object to array. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function get_matrix( $depths ) { | |
$all_users = $this->get_all_users(); | |
$depths = [3, 3, 3]; | |
$matrix = []; | |
for ( $level = 0; $level < count( $depths ); $level++ ) { | |
$total_members = pow( $depths[$level], $level + 1 ); | |
$members = json_decode( json_encode( array_splice( $all_users, 0, $total_members ), JSON_FORCE_OBJECT ) ); | |
$members_arr = json_decode( json_encode( $members ), TRUE ); | |
$iter = new RecursiveIteratorIterator( new RecursiveArrayIterator( $members ), RecursiveIteratorIterator::SELF_FIRST ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function test_reference_tree_building() { | |
$source = [ | |
1 => ['name' => 'Parent One', 'parent_id' => null], 2 => ['name' => 'Parent Two', 'parent_id' => null], | |
3 => ['name' => 'Child One', 'parent_id' => 1], 4 => ['name' => 'Child Two', 'parent_id' => 1], | |
5 => ['name' => 'Child Three', 'parent_id' => 2], 6 => ['name' => 'Child Four', 'parent_id' => 5], | |
7 => ['name' => 'Child Five', 'parent_id' => 2], 8 => ['name' => 'Child Six', 'parent_id' => 3], | |
9 => ['name' => 'Child Seven', 'parent_id' => 6] | |
]; | |
$nested = []; | |
foreach ( $source as &$s ) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Load Elementor styles on all pages in the head to avoid CSS files being loaded in the footer | |
*/ | |
function elementor_css_in_head(){ | |
if(class_exists('\Elementor\Plugin')){ | |
$elementor = \Elementor\Plugin::instance(); | |
$elementor->frontend->enqueue_styles(); | |
} | |
if(class_exists('\ElementorPro\Plugin')){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
if [ "$EUID" -ne 0 ];then | |
>&2 echo "This script requires root level access to run" | |
exit 1 | |
fi | |
if [ -z "${WORDPRESS_DB_PASSWORD}" ]; then | |
>&2 echo "WORDPRESS_DB_PASSWORD must be set" | |
>&2 echo "Here is a random one that you can paste:" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Day | Name | Solution | |
---|---|---|---|
1 | Candies | https://scrimba.com/scrim/co0a64754be538039f0f7561d | |
2 | Deposit Profit | https://scrimba.com/scrim/co1634148af237abe36bd3b48 | |
3 | Chunky Monkey | https://scrimba.com/scrim/co1784708af85897a1e657e17 | |
4 | Century from year | https://scrimba.com/scrim/co2f447838bce36b29c1babf7 | |
5 | Reverse a string | https://scrimba.com/scrim/co4b84d0d934f77c4c8d0b49e | |
6 | Sort by length | https://scrimba.com/scrim/co51b4537a82ef1d8b2b8966e | |
7 | Count vowel consonant | https://scrimba.com/scrim/co8cf4a59b3a0e6fa5c12bbfa | |
8 | Rolling dice | https://scrimba.com/scrim/cob0240939633eaf66e463df8 | |
9 | Sum Odd Fibonacci Numbers | https://scrimba.com/scrim/coc994da6b0c09200edef57f3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// debug config for running project under vscode debugger | |
{ | |
"version": "0.2.0", | |
"configurations": [ | |
{ | |
"trace": true, | |
"name": "Chrome Debug", | |
"type": "chrome", | |
"request": "launch", | |
"url": "http://localhost:8000/", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
## Installation: | |
# - make a file, called `git-rsync` in a directory, covered by your $PATH variable; | |
# - `chmod a+x` this file. | |
# - do the same for `listfiles` script | |
# | |
## Usage: | |
# 1. Syncing "dirties" (all the files you can see in the `git status` output) | |
# - before commiting, issue `git-rsync login@host:/destination/path/` command to sync all local changes to your stage server |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Copy all modifications to a file from one repo to another | |
for c in `git --git-dir=../path/to/repo/.git log --reverse --pretty=tformat:"%H" -- path/to/file`; do | |
git --git-dir=../path/to/repo/.git format-patch --keep-subject -1 --stdout $c | git am --3way --keep; | |
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Navigate to a wordpress edit page for any post and run one of the code sections below in a javascript console to get the names/info for all blocks available to gutenberg on your site. */ | |
/* log all block info to console */ | |
console.log(wp.data.select( "core/blocks" ).getBlockTypes()); | |
/* log all block names to console */ | |
wp.data.select( "core/blocks" ).getBlockTypes().forEach(function(element) { | |
console.log(element['name']); | |
}); |