Skip to content

Instantly share code, notes, and snippets.

@alan-ps
alan-ps / migrate_plus.migration.my_group_d7_menu_links.yml
Created July 1, 2020 20:08
Menu links migrate example: import main-menu links which associated with article and page content type.
@alan-ps
alan-ps / reactjs_persisting_state_to_local_storage.js
Created February 14, 2020 12:55
Persisting the State to the Local Storage
// See: https://egghead.io/lessons/javascript-redux-persisting-the-state-to-the-local-storage
const loadState = () => {
try {
const serializedState = localStorage.getItem('state');
if (serializedState === null) {
return undefined;
}
return JSON.parse(serializedState);
} catch (err) {

Configuration split

Config Split allows user to define a set of configuration files that get exported to a different directory from the rest of the config files. When that split is active, config files in that directory override values in the default set.

Example 1: the views_ui module should be enabled on dev environment only and aggregation should be disabled there.
  1. drush cex;
  2. Create a new split (admin/config/development/configuration/config-split), i.e. dev and enable it;
  3. Add views_ui module to a blacklist and system.performance configuration to a greylist;
  4. Change aggregation configuration;
  5. drush cex.
@alan-ps
alan-ps / reactjs_app_routing.js
Created August 15, 2019 08:06
An example of simple routing implementation for your React application.
import React, {Component} from 'react';
import { Redirect, BrowserRouter, Route, Switch } from "react-router-dom";
function App() {
let auth = false;
return (
<BrowserRouter>
<Switch>

A generator allows you to write code that uses foreach to iterate over a set of data without needing to build an array in memory, which may cause you to exceed a memory limit, or require a considerable amount of processing time to generate.

Example
<?php

/**
 * Helper function to get $count of even numbers.
 */
function func($count) {
@alan-ps
alan-ps / php_private_method_call.md
Last active August 3, 2019 15:12
Call private methods and private properties from outside a class in PHP.
<?php

class MyClass {

  private function somePrivateMethod() {
    echo 'This method is private!';
  }

}

Functional inheritance

function Animal() {
  var that = {};
  that.eats = true;
  return that;
}

function Dog() {
 var that = Animal();

Overview

The keyword static is similar to self, except, that it related to a class which calls a method and do not related to a class which contains a call.

Example

<?php
  
abstract class Drink {
  private $category;

Alternate Null Type Syntax

<?php

function myFunc(?MyObject $myObj) {
  echo 'Hello World!';
}

myFunc(null); // this is allowed