Skip to content

Instantly share code, notes, and snippets.

View lihourchhin's full-sized avatar
🎯
Focusing

Lihour lihourchhin

🎯
Focusing
View GitHub Profile
@lihourchhin
lihourchhin / load_dotenv.sh
Created October 2, 2021 05:18 — forked from mihow/load_dotenv.sh
Load environment variables from dotenv / .env file in Bash
if [ ! -f .env ]
then
export $(cat .env | xargs)
fi
@lihourchhin
lihourchhin / MessengerChat.js
Created August 14, 2021 04:13
Facebook Messenger Chat Plugin with NextJS
import React, { Component } from 'react'
import PropTypes from 'prop-types'
/**
* Utils
*/
const removeElementByIds = ids => {
ids.forEach(id => {
const element = document.getElementById(id)
if (element && element.parentNode) {
@lihourchhin
lihourchhin / chmodr.sh
Created January 16, 2021 04:37 — forked from francisbyrne/chmodr.sh
Recursive chmod script for dirs and/or files
#!/bin/sh
#
# chmodr.sh
#
# author: Francis Byrne
# date: 2011/02/12
#
# Generic Script for recursively setting permissions for directories and files
# to defined or default permissions using chmod.
#
@lihourchhin
lihourchhin / fetch_data_in_react.js
Created November 2, 2020 01:41 — forked from mittalyashu/fetch_data_in_react.js
Fetch Data From RSS Feed In React
class FetchDataFromRSSFeed extends Component {
constructor() {
super();
this.state = {
recentBlogPost: {
name: '',
url: ''
}
}
}
@lihourchhin
lihourchhin / FactoryTests.kt
Created October 13, 2020 05:39 — forked from sombochea/FactoryTests.kt
Simple Factory Pattern on Kotlin
package com.cubetiqs.factory
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test
class FactoryTests {
@Test
fun factoryTest() {
val carA = CarFactory(CarType.CAR_A).getCar()
@lihourchhin
lihourchhin / FactoryTests.kt
Created October 13, 2020 05:39 — forked from sombochea/FactoryTests.kt
Simple Factory Pattern on Kotlin
package com.cubetiqs.factory
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test
class FactoryTests {
@Test
fun factoryTest() {
val carA = CarFactory(CarType.CAR_A).getCar()
@lihourchhin
lihourchhin / node_nginx_ssl.md
Created June 28, 2020 19:18 — forked from bradtraversy/node_nginx_ssl.md
Node app deploy with nginx & SSL

Node.js Deployment

Steps to deploy a Node.js app to DigitalOcean using PM2, NGINX as a reverse proxy and an SSL from LetsEncrypt

1. Sign up for Digital Ocean

If you use the referal link below, you get $10 free (1 or 2 months) https://m.do.co/c/5424d440c63a

2. Create a droplet and log in via ssh

I will be using the root user, but would suggest creating a new user

@lihourchhin
lihourchhin / advanced-memo.md
Created February 25, 2020 01:43 — forked from slikts/advanced-memo.md
Advanced memoization and effects in React

Advanced memoization and effects in React

Memoization is a somewhat fraught topic in the React world, meaning that it's easy to go wrong with it, for example, by [making memo() do nothing][memo-pitfall] by passing in children to a component. The general advice is to avoid memoization until the profiler tells you to optimize, but not all use cases are general, and even in the general use case you can find tricky nuances.

Discussing this topic requires some groundwork about the technical terms, and I'm placing these in once place so that it's easy to skim and skip over:

  • Memoization means caching the output based on the input; in the case of functions, it means caching the return value based on the arguments.
  • Values and references are unfortunately overloaded terms that can refer to the low-level implementation details of assignments in a language like C++, for example, or to memory allocation (i.e., value and reference types in C#), but that should just be ignored in JavaScript, because "pass b
@lihourchhin
lihourchhin / gitcom.md
Created February 22, 2020 09:35 — forked from jednano/gitcom.md
Common git commands in a day-to-day workflow

Git Cheat Sheet

Initial Setup

Create an empty git repo or reinitialize an existing one

$ git init
@lihourchhin
lihourchhin / gist:136a128f064156d6656ca0e741bf7fe9
Created January 25, 2020 14:41 — forked from yesvods/gist:51af798dd1e7058625f4
Merge Arrays in one with ES6 Array spread
const arr1 = [1,2,3]
const arr2 = [4,5,6]
const arr3 = [...arr1, ...arr2] //arr3 ==> [1,2,3,4,5,6]