Skip to content

Instantly share code, notes, and snippets.

View phunguyen19's full-sized avatar

Raymond Phu Nguyen phunguyen19

View GitHub Profile
@phunguyen19
phunguyen19 / drupal-8-node-field-reference-entity-url-lable.twig
Last active June 10, 2022 13:42
drupal 8, display node field reference entity (label and url)
{#
/**
* This snippet works with Drupal 8.3.x
*
* Template for using: node.html.twig.
*
* This code below works with conditions:
* - templates for using: node.html.twig and node convention templates
* - field is a reference to taxonomy_term entity name : "category"
* - field machine name "field_category"
@phunguyen19
phunguyen19 / page-template-content-type.php
Last active June 10, 2022 13:42
drupal 8 custom page template (suggestion) based on content types (page--[content-type].html.twig)
<?php
/**
* Implements hook_theme_suggestions_HOOK_alter().
*
* This hook for adding a custom suggestion page template.
*
* Place this function in your THEME_NAME.theme file.
* then you can use the template page--[content-type].html.twig
*
* Tested and worked with Drupal Version 8.3.x
@phunguyen19
phunguyen19 / smooth-scroll-top.js
Last active June 10, 2022 14:51
jquery smooth scroll top
/**
* Smooth scroll top
*/
(function($){ $(function(){
$("a[href='#top']").click(function(event) {
event.preventDefault();
$("html, body").animate({ scrollTop: 0 }, 1000);
});
@phunguyen19
phunguyen19 / install-php7-extensions.sh
Created September 27, 2017 04:48 — forked from Jacksgong/install-php7-extensions.sh
linux ubuntu install php7 and neccessary extensions
sudo apt install php7.0-common php7.0-fpm php7.0-cli php7.0-json php7.0-mysql php7.0-curl php7.0-intl php7.0-mcrypt php-pear php7.0-gd php7.0-zip php7.0-xml php7.0-mbstring
@phunguyen19
phunguyen19 / SerializerWithPager.php
Last active June 10, 2022 13:42 — forked from shadcn/SerializerWithPager.php
drupal 8 View plugin Serializer with paging
<?php
namespace Drupal\MODULE_NAME\Plugin\views\style;
use Drupal\rest\Plugin\views\style\Serializer;
/**
* The style plugin for serialized output formats with pager.
*
* @ingroup views_style_plugins
@phunguyen19
phunguyen19 / drupalLoginRedirect.php
Last active June 10, 2022 13:42
drupal redirect after login
<?php
/**
* Implements hook_user_login().
*/
function mymodule_user_login(\Drupal\user\UserInterface $account) {
// Default login destination to the dashboard.
$current_request = \Drupal::service('request_stack')->getCurrentRequest();
if (!$current_request->query->get('destination')) {
$current_request->query->set(
@phunguyen19
phunguyen19 / solidity-compare-string.sol
Last active June 10, 2022 13:56
solidity compare strings
// Compare 2 strings in solidity ^0.4.23;
function compareStrings(string a, string b) internal pure returns (bool){
return keccak256(a) == keccak256(b);
}
@phunguyen19
phunguyen19 / lodash_merge_by_key.js
Last active June 10, 2022 14:00
js lodash merge 2 arrays of object by key
// Source reference: https://stackoverflow.com/questions/38612972/how-to-merge-two-array-of-object-by-using-lodash
_.mixin({
mergeByKey(arr1, arr2, key) {
const criteria = {};
criteria[key] = null;
return _.map(arr1, (item) => {
criteria[key] = item[key];
return _.merge(item, _.find(arr2, criteria));
});
@phunguyen19
phunguyen19 / commands.md
Last active June 10, 2022 14:21
linux useful command
# List all process of program "node"
ps -fe | preg node

# To list any process listening to the port 8080:
lsof -i:8080

# To kill any process listening to the port 8080
kill $(lsof -t -i:8080)
# or more violently:
@phunguyen19
phunguyen19 / citations
Created March 18, 2019 03:34 — forked from bussiere/citations
citations quote informatic informatique quotes computer science
“The first 90% of the code accounts for the first 90% of the development time. The remaining 10% of the code accounts for the other 90% of the development time.” – Tom Cargill
“In order to understand recursion, one must first understand recursion.” – Author Unknown
“I have always wished for my computer to be as easy to use as my telephone; my wish has come true because I can no longer figure out how to use my telephone.” – Bjarne Stroustrup
“A computer lets you make more mistakes faster than any other invention in human history, with the possible exceptions of handguns and tequila.” – Mitch Ratcliffe
“There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies, and the other way is to make it so complicated that there are no obvious deficiencies. The first method is far more difficult.” -C.A.R. Hoare
“The gap between theory and practice is not as wide in theory as it is in practice.” – Author Unknown
“If builders built buildings the way progra