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);

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);
@lhuria94
lhuria94 / old-mode-100755-new-mode-100644.md
Created March 29, 2018 07:51
How do I remove files saying “old mode 100755 new mode 100644” from unstaged changes in Git?

Vá até o seu repositório e execute

git config core.filemode false

@lhuria94
lhuria94 / rebase.md
Created January 6, 2018 08:20
Ultimate rebase-onto-master guide

Rebase "web-123-my-branch" onto master:

if you're the only person who is working on a branch...

$ git checkout web-123-my-branch # make sure you're on the right branch
$ git fetch # update remote refs
$ git rebase origin/master # perform the rebase onto the current state of master
  # for each conflict, edit file, resolve conflicts, git add -u <file>, git rebase --continue
$ git push -f origin web-123-my-branch # overwrite remote branch with newly rebase branch
@lhuria94
lhuria94 / better_tabledrag.php
Created November 22, 2017 10:59
Drupal table drag example in form An example of using a Drupal tabledrag table without the need of creating a theme function for the complete form. This makes it a lot easier to build a form which contains multiple form elements/fieldsets.
<?php
/**
* @file
* A tabledrag example - without theming the whole form.
*/
/**
* Implements hook_menu().
*/