Skip to content

Instantly share code, notes, and snippets.

View jw-12138's full-sized avatar

Jacky Wong jw-12138

View GitHub Profile
require('dotenv').config()
const {
DynamoDBClient,
PutItemCommand,
UpdateItemCommand,
DeleteItemCommand,
GetItemCommand
} = require('@aws-sdk/client-dynamodb') // ^3.264.0
@jw-12138
jw-12138 / copy-static-folder.js
Last active November 21, 2021 11:53
Providing a way to copy static file folders to the distribution folder, works pretty nice for parcel v2 or v1. or whatever other packaging tools you are using.
const chokidar = require('chokidar');
const fs = require('fs');
const path = require('path')
const ncp = require('ncp').ncp
let data = fs.readFileSync(path.join(__dirname, 'package.json'), {
encoding: "utf-8",
flag:'r'
})
let watch = true
@jw-12138
jw-12138 / bench.js
Last active November 18, 2021 12:45
browser benchmark testing script?
(function (){
console.log('Calculating...')
let index = 0
let test_seconds = 2
let start_time = Date.now()
let interval_time = 0
while(interval_time - start_time <= test_seconds * 1000){
interval_time = Date.now()
index++
}
@jw-12138
jw-12138 / server.js
Created April 13, 2021 02:06
Local NodeJS dev server ( no cache )
const express = require('express')
const app = express()
const port = 80
const ip = '127.0.0.1'
app.use(express.static('./'))
let setCache = function (req, res, next) {
res.set('Cache-control', `no-store`)
next()
@jw-12138
jw-12138 / getParam.js
Last active August 17, 2020 02:28
get url parameters using js
let getParam = (p) => {
let obj = {}
let param = window.location.search.split('?')
param = param[1]
if(!param) return false
param.split('&').forEach(el => {
let element_arr = el.split('=')
obj[element_arr[0]] = element_arr[1]
});
return obj[p] ? obj[p] : false
@jw-12138
jw-12138 / ie_version.js
Last active August 17, 2020 02:29
A JavaScript function which detects the version of IE in a very simple way. This code was originally developed by Apple.
var isIE = function(ver) {
var b = document.createElement('b');
b.innerHTML = '<!--[if IE ' + ver + ']><i></i><![endif]-->';
return b.getElementsByTagName('i').length === 1;
}