Skip to content

Instantly share code, notes, and snippets.

View dalenguyen's full-sized avatar
🎮
Playing with code <>

Dale Nguyen dalenguyen

🎮
Playing with code <>
View GitHub Profile
@dalenguyen
dalenguyen / webhook-payload-encrypt-decrypt.js
Created February 27, 2023 06:37
Webhooks payload encrypt & decrypt
const CryptoJS = require('crypto-js')
const secret = 'my-secret-key' // shared by producer & consumer
// Producer
const payload = {
name: 'John Doe',
email: 'john.doe@example.com',
phone: '555-1234',
}
@dalenguyen
dalenguyen / waitForElement.js
Created April 2, 2020 18:48
Wait for Element to Exist (JavaScript)
// HTML
<!-- Comment or Uncomment the div for return true / false -->
<div id="the-element"></div>
// JAVASCRIPT
// Wait for element for 4s
const waitForElement = async (elementId, timeWait = 4) => {
return new Promise((resolve, reject) => {
let tempTime = 0
const checkExist = setInterval(function() {
@dalenguyen
dalenguyen / firebase-custom-claims-wordpress.js
Created December 2, 2019 01:37
Work With Firebase Custom Claims in WordPress
// https://gist.github.com/dalenguyen/650ab896086f3213e81eda5e96efe3d3
(function ($) {
'use strict';
$(document).ready(function () {
const showFirestoreDatabase = () => {
...
}
// We won't call the function directly here
// showFirestoreDatabase()
@dalenguyen
dalenguyen / add_custom_firebase_js_wordpress.php
Last active March 20, 2020 21:48
(Integrate Firebase PRO): Add custom Firebase JavaScript to WordPress
// functions.php
// Custom JavaScript for Firebase
function custom_firebase_scripts_function()
{
wp_enqueue_script('custom_firebase', get_template_directory_uri() . '/js/custom-firebase.js', array('firebase_app', 'firebase_auth', 'firebase_database', 'firebase_firestore', 'firebase'));
}
add_action('wp_enqueue_scripts', 'custom_firebase_scripts_function');
@dalenguyen
dalenguyen / add_wordpress_shortcode.php
Created November 2, 2019 17:19
Add shortcode to WordPress
// functions.php
// custom firebase short code
function custom_firebase_func($atts)
{
return "<div id='custom-firebase'>Test</div>";
}
add_shortcode('custom_firebase', 'custom_firebase_func');
@dalenguyen
dalenguyen / retrieve_firestore_data_for_wordpress.js
Created November 2, 2019 17:17
(Integrate Firebase PRO): Get data from Firestore and display on Wordpress
(function ($) {
'use strict';
$(document).ready(function () {
const showFirestoreDatabase = () => {
const db = firebase.firestore();
const firestoreEl = jQuery('#custom-firebase');
// You can get the collectionName and documentName from the shortcode attribute
const collectionName = 'users';
const documentName = ‘document-1'
@dalenguyen
dalenguyen / .bash_profile_GIT
Last active June 19, 2019 15:08
Git shortcuts in Bash
# Github
alias gs="git status"
alias gd="git diff"
alias gp="git pull"
# Git finish will push to current branch
# Eg. gf "commit message"
gf() {
CURRENT_BRANCH="$(git rev-parse --abbrev-ref HEAD)"
git add . && git commit -m "$1" && git push origin "$CURRENT_BRANCH"
@dalenguyen
dalenguyen / Dockerfile_NODE
Last active October 12, 2018 20:06
Dockerfile from a Node project
# I'm using NODE 6, you can change to NODE 8 or 10
FROM node:6
# This will be the current working dir
WORKDIR /usr/src/app
# I copy entire project to the working dir
COPY . .
# Root commands
@dalenguyen
dalenguyen / zsh.md
Created September 29, 2016 19:24 — forked from tsabat/zsh.md
Getting oh-my-zsh to work in Ubuntu
@dalenguyen
dalenguyen / cpt-genesis.php
Created August 26, 2016 20:34 — forked from neilgee/a-cpt.php
CPT (Custom Post Type) Genesis Theme - Plugin - WordPress Example
<?php
/*
Plugin Name: Event Custom Post Type
Plugin URI: http://wpbeaches.com/create-custom-post-types-in-genesis-child-theme-in-wordpress/
Description: Custom Post Types for Event
Author: Neil Gee
Version:1
Author URI:http://wpbeaches.com
*/