Skip to content

Instantly share code, notes, and snippets.

View phunguyen19's full-sized avatar

Raymond Phu Nguyen phunguyen19

  • Ho Chi Minh City, Vietnam
  • 11:22 (UTC +07:00)
  • LinkedIn in/phunguyen19
View GitHub Profile
@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
@phunguyen19
phunguyen19 / docker-compose.yml
Last active May 5, 2022 16:30
start wordpress docker compose
version: "3.9"
services:
db:
image: mysql:5.7
volumes:
- db_data:/var/lib/mysql
- ./docker/my.cnf:/etc/my.cnf
restart: always
environment:
@phunguyen19
phunguyen19 / ec2-user-data-install-apache-server.sh
Created September 23, 2020 16:01
aws ec2 user data install apache server
#!/bin/bash
# Install Apache server
yum update -y
yum install -y httpd.x86_64
systemctl start httpd.service
systemctl enable httpd.service
echo "Hello world $(hostname -f)" > /var/www/html/index.html
@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 / 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 / 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 / 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
version: '3'
networks:
workspaces:
driver: bridge
services:
zookeeper:
image: confluentinc/cp-zookeeper:5.3.1
restart: always
@phunguyen19
phunguyen19 / is_duplicate.js
Created May 20, 2019 10:46
js check if array is duplicate
// Using ES 6, shortest and most readable solution
(new Set(myArray)).size !== myArray.length
// Using Array.some, this is fastest solution
myArray.some((value, index, array) => array.includes(value, index + 1))
// Using filter
passphrases.filter(function (value, index, self) { return self.indexOf(value) === index; }).length !== passphrases.length
// Source for benchmark: https://jsbench.me/mqjvw8exl9
@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);
}