Skip to content

Instantly share code, notes, and snippets.

View henrytran9x's full-sized avatar

Henry Tran henrytran9x

View GitHub Profile
@henrytran9x
henrytran9x / interview.md
Last active May 31, 2022 04:31
Interview Question

Javascript

Question 1

In what order will the numbers 1-4 be logged to the console when the code below is executed? Why?

(function() {
    console.log(1); 
    setTimeout(function(){console.log(2)}, 1000); 
    setTimeout(function(){console.log(3)}, 0); 

console.log(4);

@henrytran9x
henrytran9x / drupal_8_twig_cheatsheet.md
Created November 30, 2019 17:00
Drupal 8 Twig cheatsheet

Drupal 8 Twig cheatsheet

Getting Drupal 8 field values in Twig

Image path: {{ file_url(content.field_name['#items'].entity.uri.value) }}

Image title text: {{ node.field_name.title }}

Entity Reference path: {{ content.field_tags[0]['#url'] }}

@henrytran9x
henrytran9x / wordpress.nginxconf
Created February 21, 2019 08:07 — forked from goblindegook/wordpress.nginxconf
Nginx virtual host configuration for WordPress
server {
listen 80;
server_name www.example.com;
rewrite ^ $scheme://example.com$request_uri?;
}
server {
listen 80;
server_name example.com;
@henrytran9x
henrytran9x / script.js
Created December 19, 2017 04:29
Call handler show popup modal bootstrap !
//Call before load modal boostrap
element.on('show.bs.modal', function () {});
//Call after load Modal bootstrap
element.on('shown.bs.modal', function (e) {})
@henrytran9x
henrytran9x / index.php
Created October 3, 2017 01:57
encryptMD5
<?php
/*
* Function create encrypt MD5
* Remember mcrypt_encrypt() not support PHP 7.0
*/
public function encryptMD5($string) {
$qEncoded = base64_encode(mcrypt_encrypt( MCRYPT_RIJNDAEL_256, md5('[MÃ_KEY]'), $string, MCRYPT_MODE_CBC, md5( md5(['[MÃ_KEY]']) ) ) );
return $qEncoded;
}
@henrytran9x
henrytran9x / query.sql
Created September 30, 2017 16:18
Query get all information columns of table
SELECT column_name, data_type, character_maximum_length, numeric_precision, numeric_scale, is_nullable, column_type, column_default, column_key, extra FROM information_schema.columns WHERE table_name = 'table_name' AND table_schema = 'name_database' ORDER BY ordinal_position
@henrytran9x
henrytran9x / query.sql
Created August 3, 2017 10:20
Demo build Schema and Query about Join !
/*** CREATE table Departments **/
CREATE TABLE Departments(
DepartmentID INT IDENTITY(1,1) PRIMARY KEY,
DepartmentName varchar(500)
);
/* Insert record into table Departments */
INSERT INTO Departments (DepartmentName) VALUES
('IT'),('HR'),('Payroll'),('Admin');
/** CREATE TABLE Employees **/
@henrytran9x
henrytran9x / function.php
Last active July 28, 2017 08:29
Auto include file *.php in by directory !
<?php
// include All file php in directory API
$dirAPI = array_filter(glob(path_dir_root), 'is_dir');
foreach($dirAPI as $dir){
foreach (glob("$dir/*.php") as $filename)
{
include $filename;
}
}
@henrytran9x
henrytran9x / function.php
Created July 21, 2017 06:44
ConvertStringToArray
<?php
public function ConvertStringToArray($str) {
$str = substr($str, 1, strlen(substr($str, 0, strlen($str)-2)));
$str = str_replace("'",'',$str);
$strs = explode(',', $str);
$arr = array();
$c_strs = count($strs);
for ($i = 0; $i < $c_strs; $i++) {
if (strpos($strs[$i],'=>') !== false) {
https://crontab.guru