Skip to content

Instantly share code, notes, and snippets.

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

Love Huria lhuria94

🏠
Working from home
View GitHub Profile
Drupal 7
// To turn on JS Aggregation
drush vset preprocess_js 1 --yes
// To clear all Cache
drush cc all
// To disable JS Aggregation
drush vset preprocess_js 0 --yes
@lhuria94
lhuria94 / git-hard-delete
Created May 12, 2021 11:07 — forked from srebalaji/git-hard-delete
Examples of git custom command
#!/bin/sh
branch=$1
if [ ! -z "$1" ]
then
git branch -D $branch
git push -d origin $branch
else
echo "Branch name is not specified"
@lhuria94
lhuria94 / pre-commit-eslint
Created August 10, 2019 09:15 — forked from shettayyy/pre-commit-eslint
Pre-commit hook for Linting JS with ESLint before commit.
#!/bin/sh
STAGED_FILES=$(git diff --cached --name-only --diff-filter=ACM | grep ".jsx\{0,1\}$")
ESLINT="$(git rev-parse --show-toplevel)/node_modules/.bin/eslint"
if [[ "$STAGED_FILES" = "" ]]; then
exit 0
fi
PASS=true
URL="http://stackoverflow.com/"
# store the whole response with the status at the and
HTTP_RESPONSE=$(curl --silent --write-out "HTTPSTATUS:%{http_code}" -X POST $URL)
# extract the body
HTTP_BODY=$(echo $HTTP_RESPONSE | sed -e 's/HTTPSTATUS\:.*//g')
# extract the status
HTTP_STATUS=$(echo $HTTP_RESPONSE | tr -d '\n' | sed -e 's/.*HTTPSTATUS://')
@lhuria94
lhuria94 / download.js
Created July 4, 2019 11:27 — forked from hutch120/download.js
Cut down for ES6 and ESLint compatibility
// download.js v4.21, by dandavis; 2008-2018. [MIT] see http://danml.com/download.html for tests/usage
// v1 landed a FF+Chrome compatible way of downloading strings to local un-named files, upgraded to use a hidden frame and optional mime
// v2 added named files via a[download], msSaveBlob, IE (10+) support, and window.URL support for larger+faster saves than dataURLs
// v3 added dataURL and Blob Input, bind-toggle arity, and legacy dataURL fallback was improved with force-download mime and base64 support. 3.1 improved safari handling.
// v4 adds AMD/UMD, commonJS, and plain browser support
// v4.1 adds url download capability via solo URL argument (same domain/CORS only)
// v4.2 adds semantic variable names, long (over 2MB) dataURL support, and hidden by default temp anchors
// https://github.com/rndme/download
export default function download (data, strFileName, strMimeType) {
@lhuria94
lhuria94 / php_object_to_array.php
Created February 5, 2019 06:04 — forked from victorbstan/php_object_to_array.php
recursively cast a PHP object to array
<?php
/*
This function saved my life.
found on: http://www.sitepoint.com/forums//showthread.php?t=438748
by: crvandyke
It takes an object, and when all else if/else/recursive functions fail to convert the object into an associative array, this one goes for the kill. Who would'a thunk it?!
*/
$array = json_decode(json_encode($object), true);
@lhuria94
lhuria94 / Vagrantfile
Last active August 6, 2018 07:05
Custom VagrantFile
# -*- mode: ruby -*-
# vi: set ft=ruby :
# All Vagrant configuration is done below. The "2" in Vagrant.configure
# configures the configuration version (we support older styles for
# backwards compatibility). Please don't change it unless you know what
# you're doing.
Vagrant.configure("2") do |config|
# The most common configuration options are documented and commented below.
# For a complete reference, please see the online documentation at
# Git Shortcuts
alias gst='git status'
alias gp='git pull origin'
alias gcod='git checkout develop'
alias gcom='git checkout master'
alias gl='git log --oneline'
alias gd='git diff'
# Drush Shortcuts
alias dca='drush cc all'
@lhuria94
lhuria94 / ReverseCalc.js
Created July 1, 2018 14:30
Refactored Reverse Calc method
handleReverseLookUp (event) {
const {
exchangeAmountPrecision,
currencyData,
conf,
exchangeRatePrecision
} = this.props;
const {currency} = this.state;
const {sendCurrency} = conf;
const el = event.target;

Drupal 8 Entity API cheat sheet

The examples here contain some hard-coded IDs. These are all examples. In your real code, you should already have the node IDs, file IDs, etc. in a variable.

Working with nodes

Load a node by NID:

$nid = 123;     // example value
$node_storage = \Drupal::entityTypeManager()->getStorage('node');
$node = $node_storage->load($nid);