Skip to content

Instantly share code, notes, and snippets.

View lukewang1024's full-sized avatar

Luke Wang lukewang1024

View GitHub Profile
@lukewang1024
lukewang1024 / page-back-forward-navigation-detection.md
Created March 15, 2020 02:30
Some useful snippets for frontend web development

Detect if the page load is from a back or forward browser navigation.

if (window.performance) {
  const navEntries = window.performance.getEntriesByType('navigation');
  if (navEntries.length > 0 && navEntries[0].type === 'back_forward') {
    console.log('As per API lv2, this page is load from back/forward');
  } else if (
    window.performance.navigation &&
 window.performance.navigation.type === window.performance.navigation.TYPE_BACK_FORWARD
@lukewang1024
lukewang1024 / tip.md
Created February 14, 2019 07:17
Use http-server to host with SSL
> mkdir -p ~/.cert; cd ~/.cert
> openssl req -newkey rsa:2048 -new -nodes -x509 -days 3650 -keyout key.pem -out cert.pem
Generating a 2048 bit RSA private key
...............................+++
..................................................................+++
writing new private key to 'key.pem'
-----
You are about to be asked to enter information that will be incorporated
@lukewang1024
lukewang1024 / log-changed-prop-or-state.js
Last active July 27, 2018 09:22
[React useful snippets] Some useful React snippets #react
class Demo extends React.Component {
componentDidUpdate(prevProps, prevState) {
for (const i in this.props) {
if (this.props[i] !== prevProps[i]) {
console.log(`prop ${i} changed from ${prevProps[i]} to ${this.props[i]}`);
}
}
for (const i in this.state) {
if (this.state[i] !== prevState[i]) {
@lukewang1024
lukewang1024 / ASCII JS Keyboard Map
Created October 31, 2017 02:11 — forked from ancestral/ASCII JS Keyboard Map
ASCII keyboard map for JavaScript keycodes (Mac)
/*
* JavaScript Keyboard Map (Mac layout)
*
*
* esc—— F1——— F2——— F3——— F4——— F5——— F6——— F7——— F8——— F9——— F10—— F11—— F12—— F13—————+
* | 27 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | ??? |
* ` ——— 1———— 2———— 3———— 4———— 5———— 6———— 7———— 8———— 9———— 0———— - ——— = ——— delete——+
* | 192 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 |
* tab———— Q———— W———— E———— R———— T———— Y———— U———— I———— O———— P———— [ ——— ] ——— \ ————+
* | 9 | 81 | 87 | 69 | 82 | 84 | 89 | 85 | 73 | 79 | 80 | 219 | 221 | 220 |
@lukewang1024
lukewang1024 / pyspark-java9-issue.md
Created October 25, 2017 11:36
Apache Spark does not work with Java 9 yet. Install Java 8 back to get it running.

When Java 9 is the default version getting resolved in the environment, pyspark will throw error below and you will see name 'xx' is not defined error when trying to access sc, spark etc. from shell / Jupyter.

Python 3.6.3 (default, Oct 19 2017, 13:58:41)
[GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.38)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
Using Spark's default log4j profile: org/apache/spark/log4j-defaults.properties
Setting default log level to "WARN".
To adjust logging level use sc.setLogLevel(newLevel). For SparkR, use setLogLevel(newLevel).
@lukewang1024
lukewang1024 / Solution.md
Created September 24, 2017 14:23
Workaround for `jest --watch` hanging on MacOS with `watchman` installed

create-react-app yarn test / npm test hangs

This is actually an issue in Jest / Watchman. Quick workaround is followed:

launchctl unload ~/Library/LaunchAgents/com.github.facebook.watchman.plist

Reference

@lukewang1024
lukewang1024 / on-jsx.markdown
Created June 18, 2017 11:44 — forked from chantastic/on-jsx.markdown
JSX, a year in

Hi Nicholas,

I saw you tweet about JSX yesterday. It seemed like the discussion devolved pretty quickly but I wanted to share our experience over the last year. I understand your concerns. I've made similar remarks about JSX. When we started using it Planning Center, I lead the charge to write React without it. I don't imagine I'd have much to say that you haven't considered but, if it's helpful, here's a pattern that changed my opinion:

The idea that "React is the V in MVC" is disingenuous. It's a good pitch but, for many of us, it feels like in invitation to repeat our history of coupled views. In practice, React is the V and the C. Dan Abramov describes the division as Smart and Dumb Components. At our office, we call them stateless and container components (view-controllers if we're Flux). The idea is pretty simple: components can'

@lukewang1024
lukewang1024 / README.md
Created March 3, 2017 15:33
Steps to enable the hidden Android Play Store in Chrome OS

Steps to enable the hidden Android Play Store in Chrome OS

  • Enable developer mode
  • Open a Crosh tab (CTRL + ALT + T), type shell, enter.
  • Run the following commands one by one.
sudo su
cp /etc/chrome_dev.conf /usr/local
mount --bind /usr/local/chrome_dev.conf /etc/chrome_dev.conf
@lukewang1024
lukewang1024 / npm_scripts_build_tool.md
Last active December 1, 2023 20:06
Notes from egghead.io course: How to Use npm Scripts as Your Build Tool

Use npm scripts as your build tool

Basic dev task composition

// Dev tasks
{
  "scripts": {
    "eslint": "eslint --cache --fix ./",
    "stylelint": "stylelint '**/*.scss' --syntax scss",
@lukewang1024
lukewang1024 / luna_pinyin.emoji.dict.yaml
Created September 30, 2016 10:18 — forked from lembacon/luna_pinyin.emoji.dict.yaml
Pinyin-Emoji Dictionary for Squirrel
# Rime dictionary
# encoding: utf-8
---
name: luna_pinyin.emoji
version: "2016.09.07"
sort: by_weight
use_preset_vocabulary: true
...