Skip to content

Instantly share code, notes, and snippets.

@wahengchang
wahengchang / repeatLoopUrl.sh
Last active Jan 8, 2021
curl url call in for loop
View repeatLoopUrl.sh
url=https://abc.com
max=999999
for ((i=1;i<=$max;i++)); do curl -v --header "Connection: keep-alive" "$url"; done
@wahengchang
wahengchang / convertToMp4.py
Created Jan 24, 2020
Python script, which convert mov, flv, avi .etc to mp4 format
View convertToMp4.py
import subprocess
import os
src = './src'
dst = './mp4'
for root, dirs, filenames in os.walk(src, topdown=False):
#print(filenames)
for filename in filenames:
print('[INFO] 1',filename)
@wahengchang
wahengchang / f2e-test-note-2019.03.22.md
Last active Mar 25, 2019
f2e-test-note-2019.03.22
View f2e-test-note-2019.03.22.md

Welcome to the Challenge

Goal

Scraping the 1000 data from this site and save it as a json file.

From this site: https://f2e-test.herokuapp.com

Username Password
View fetchMacauNews.js
// example of fetching a
(async function(){
const fetch = require('node-fetch')
const fs = require('fs')
const cheerio = require('cheerio')
const html = await fetch(`http://www.macaodaily.com/html/2018-11/25/node_2.htm`).then(res => res.text())
const path = `./temp/${year}-${month}`
@wahengchang
wahengchang / nest-file-under-directory.js
Last active Mar 16, 2018
It is a script of printing and counting specific file under directory
View nest-file-under-directory.js
const fs = require('fs');
Array.prototype.remove = function(data) {
const dataIdx = this.indexOf(data)
if(dataIdx >= 0) {
this.splice(dataIdx ,1);
}
return this.length;
}
View gist:a3edb3a6ea7fad13872a021d1c27f706
/*
JavaScript Caesar shift
by Evan Hahn (evanhahn.com)
* * * * * * * * * * * *
For small occasions (like month-anniversaries), I like to make little websites
for people that only "unlock" on the right day.
View window.addEventListener.scroll.js
window.addEventListener('scroll', function(){
console.log(window.pageYOffset)
})
@wahengchang
wahengchang / ShareCom.js
Last active Mar 31, 2020
Unit test, mocking components
View ShareCom.js
import { InstallCom } from 'installComponent' //installed by npm
import UserCom from './userComponent'
export class ShareCom extends Component {
render() {
return (
<div>
<InstallCom para1='title1'/>
<UserCom para2='title2' />
</div>
@wahengchang
wahengchang / unit-test-connected-component.js
Created Feb 1, 2018
unit-test-connected-component.js
View unit-test-connected-component.js
import React from 'react'
import { connect } from 'react-redux'
import { mount, shallow } from 'enzyme'
import ToastList from '../../../src/components/common/ToastList'
jest.mock('../../../src/components/common/ToastList/ToastItem/index.js', () =>
(props) => <mock-toast-item id={props.id}>
{props.msg}
</mock-toast-item>
)