Skip to content

Instantly share code, notes, and snippets.

View zohoMatt's full-sized avatar
🏠
Working from home

MattZuo zohoMatt

🏠
Working from home
  • Raleigh, NC, US
View GitHub Profile
@zohoMatt
zohoMatt / promise.js
Created January 28, 2021 22:54
Implementation of basic features of Promise.
const STATES = {
PENDING: 'Pending',
RESOLVED: 'Resolved',
REJECTED: 'Rejected'
}
class Promise {
constructor(executor) {
const tryCall = callback => Promise.try(() => callback(this.value));
const invokes = [];
const callLater = getMethod => callback => new Promise(resolve => invokes.push(() => resolve(getMethod()(callback))));
matrix:
include:
- os: osx
osx_image: xcode10.2
language: node_js
node_js: "10"
env:
- ELECTRON_CACHE=$HOME/.cache/electron
- ELECTRON_BUILDER_CACHE=$HOME/.cache/electron-builder
@zohoMatt
zohoMatt / promise-concurrency.js
Created February 27, 2020 22:54
Concurrency control with Promise
// Async function
const request = i => new Promise((resolve, reject) => {
console.log(`No.${i} gets started.`);
setTimeout(() => {
resolve(`No.${i} gets resolved.`);
console.log(`No.${i} gets resolved.`);
}, 1000);
});
// Create a list of parameters
@zohoMatt
zohoMatt / printM3uFile.js
Last active December 14, 2016 13:21
Print .m3u file from https://iptv.tsinghua.edu.cn .
function printM3uFile() {
let $btns = $('[target="_blank"]');
let address = $.makeArray($btns.map((i, btn) => $(btn).attr('href')))
.map(n => n.split('=')[1].split('&')[0]);
let names = $.makeArray($btns.map((i, btn) => $(btn).text()));
let configure = address.map((n, i) => `#EXTINF:-1 group-title="all",${names[i]}<br>https://iptv.tsinghua.edu.cn/hls/${n}.m3u8`);
let content = document.createElement('div');
content.innerHTML = `<div>#EXTM3U<br><br>${configure.join('<br>')}</div>`;
document.body.innerHTML = '';
@zohoMatt
zohoMatt / changeVisibility.js
Last active April 21, 2018 13:21
Change the settings for the visibility of blogs, so that only users in your 'Friends Circle' can read them.
function changeVisibility() {
const loadingTime = 2000;
const s = document.createElement("script");
s.setAttribute("src","https://lib.sinaapp.com/js/jquery/2.0.3/jquery-2.0.3.min.js");
s.onload = () => {
const timer = setInterval(() => {
$(document).scrollTop(50000);
}, loadingTime)
@zohoMatt
zohoMatt / change_git_history.sh
Created September 25, 2016 15:21
Change git-commit user's information
#!/bin/sh
git filter-branch --env-filter '
# user specified
OLD_EMAIL="[email protected]"
CORRECT_NAME="correctGitHubName"
CORRECT_EMAIL="[email protected]"
if [ "$GIT_COMMITTER_EMAIL" = "$OLD_EMAIL" ]
then
@zohoMatt
zohoMatt / enable_ipv6.sh
Last active September 25, 2016 15:45
Activate IPv6 in Tsinghua network
#!/usr/bin/bash
IP4=$(ifconfig | grep "59.66.[0-9]*\.[0-9]*" | cut -d ' ' -f3) # your IPv4 address
sudo ifconfig gif0 create
sudo ifconfig gif0 tunnel $IP4 166.111.21.1
sudo ipconfig set gif0 MANUAL-V6 2402:f000:1:1501:200:5efe:$IP4 64
sudo route add -inet6 ::/0 -interface gif0
@zohoMatt
zohoMatt / send_mail.py
Last active May 19, 2016 12:46
sending a html mail using python
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.image import MIMEImage
from email.mime.text import MIMEText
def send_qr_mails(attach_path):
from_address = "xxxxxxxx" # sender's mail address
pwd = 'xxxxx' # sender's password
to_address = 'xxxxx' # receiver's address