Skip to content

Instantly share code, notes, and snippets.

View anver's full-sized avatar
🏠
Working from home

Anver Sadutt anver

🏠
Working from home
View GitHub Profile
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.
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 );
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 ) {
@anver
anver / elementorcssinhead.php
Created September 24, 2020 21:03 — forked from nicomollet/elementorcssinhead.php
Load Elementor styles on all pages in the head to avoid CSS files being loaded in the footer
<?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')){
@anver
anver / ubuntu_install.sh
Created December 10, 2020 19:07 — forked from nginx-gists/ubuntu_install.sh
Automating Installation of WordPress with NGINX Unit on Ubuntu
#!/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:"
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
@anver
anver / launch.json
Created February 21, 2021 17:17 — forked from jarshwah/launch.json
Webpack Source Maps with vscode debugging
// 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/",
@anver
anver / git-rsync.sh
Created April 23, 2021 20:53 — forked from mityukov/git-rsync.sh
Sync only files, added or modified since last commit
#!/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
@anver
anver / git-copy-file-history.sh
Created April 24, 2021 06:27 — forked from joeyates/git-copy-file-history.sh
Copy a commits from one Git repo to another
# 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
@anver
anver / list_blocks.js
Created November 16, 2021 11:28 — forked from techlemur/list_blocks.js
get all available gutenberg block info for your site with javascript
/* 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']);
});