Skip to content

Instantly share code, notes, and snippets.

View maxjing's full-sized avatar

Jing Wen maxjing

View GitHub Profile
package com.JJ;
import java.util.Stack;
public class Main {
static Stack<Integer> nums;
public static void main(String[] args) {
binary(11);
while(!nums.isEmpty()){
System.out.printf("%d",nums.peek());
const lighthouse = require("lighthouse");
const chromeLauncher = require("chrome-launcher");
function launchChromeAndRunLighthouse(type, page, timestamp, res) {
const relativePath = `reports/${type}/${page}/${timestamp}.json`;
let opts = {
chromeFlags: ["--no-sandbox", "--disable-gpu", "--headless"],
extraHeaders: { Cookie: "split_tcv=100" }
};
let lighthouse_config_accessibilityOnly = {
@maxjing
maxjing / time.js
Created January 23, 2019 19:28
timestamp
Date.prototype.customFormat = function(formatString) {
var YYYY,
YY,
MMMM,
MMM,
MM,
M,
DDDD,
DDD,
DD,
@maxjing
maxjing / awsprint.js
Created January 19, 2019 03:59
awsprint.js
// await execa.shell(
// `aws s3 ls way-accessibility/reports/${type}/hp --recursive | sort | tail -n 10 | awk '{ print $4}' >./reports/trendData/label/${type}.txt`
// );
@maxjing
maxjing / readline.js
Created January 19, 2019 00:27
javascript readline
const instream = fs.createReadStream(
path.join(__dirname, `../reports/trendData`, `${type}.json`)
);
const outstream = new stream();
const rl = readline.createInterface(instream, outstream);
const labels = [];
rl.on("line", function(line) {
labels.push(line.slice(-19, -5));
});
@maxjing
maxjing / expressjs_fetchurl.js
Last active March 28, 2019 19:48
order of promise
function get(url) {
return new Promise((resolve, reject) => {
fetch(url)
.then(res => res.json())
.then(data => resolve(data))
.catch(err => reject(err));
});
}
#example
@maxjing
maxjing / getMostRecentLocalFileName.js
Created January 15, 2019 04:34
getMostRecentLocalFileName
function getMostRecentLocalFileName(dir) {
var files = fs.readdirSync(dir);
return _.max(files, function(f) {
var fullpath = path.join(dir, f);
return fs.statSync(fullpath).ctime;
});
}
@maxjing
maxjing / axios.js
Created January 15, 2019 00:13
axios mutiple request promise all
_getAllStaticRDCData = () => {
var self = this;
axios
.all([
this.getStaticRDCData("hp"),
this.getStaticRDCData("srp"),
this.getStaticRDCData("ldp")
])
.then(
axios.spread(function(hp, srp, ldp) {
@maxjing
maxjing / paralle_curl.js
Created January 10, 2019 23:20
parallel run commend on terminal
urls=("http://way-api.rdc-dev.moveaws.com/prod/hptest" "http://way-api.rdc-dev.moveaws.com/prod/srptest" "http://way-api.rdc-dev.moveaws.com/prod/ldptest" "http://way-api.rdc-dev.moveaws.com/beta/hptest" "http://way-api.rdc-dev.moveaws.com/beta/srptest" "http://way-api.rdc-dev.moveaws.com/beta/ldptest")
for url in "${urls[@]}"
do
curl "$url"
done
@maxjing
maxjing / clearFolder.js
Created January 2, 2019 21:56
clear all files of a folde
const clearFolder = directory => {
fs.readdir(directory, (err, files) => {
if (err) throw err;
for (const file of files) {
fs.unlink(path.join(directory, file), err => {
if (err) throw err;
});
}
});