Skip to content

Instantly share code, notes, and snippets.

View junhan-z's full-sized avatar
🐽
tomorrow was your yesterday

Junhan junhan-z

🐽
tomorrow was your yesterday
View GitHub Profile
@junhan-z
junhan-z / table-of-contents.js
Last active February 7, 2021 02:02
Gatsby Table of Content implementation
import React from "react"
import kebabCase from "lodash/kebabCase"
class HeaderNode {
constructor(value, depth) {
this.value = value
this.depth = depth
this.children = []
}
@junhan-z
junhan-z / rename_master_branch.sh
Last active February 6, 2021 08:40
Change "master" branch to "main"
# rename local master branch to "main"
git branch -m master main
# push to remote branch as "main"
git push origin main:main
# go to github, change the default branch, which usually to be "master"
# delete remote "master" branch
git push origin --delete master
@junhan-z
junhan-z / zhihu-fetch.rb
Created May 19, 2020 06:25
Get content from Zhihu via Ruby
require 'net/http'
zhihu = 'https://zhuanlan.zhihu.com/p/139146103'
uri = URI(zhihu)
# user agent is necessary otherwise Zhihu throws 400
user_agent = 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.86 Safari/537.36'
res = Net::HTTP.start(uri.hostname, uri.port, :use_ssl => true) do |http|. # :use_ssl => true for the uri is https
http.request(Net::HTTP::Get.new(uri, {'User-Agent' => user_agent}))
@junhan-z
junhan-z / tag-generator.py
Created March 26, 2020 01:03
Generate tag directories for Jekyll
#!/usr/local/bin/python3
import re
import glob
import os
TAG_TEMPLATE = '''---
layout: tag_pages
title: "{tag}"
tag: {tag}
@junhan-z
junhan-z / get_last_argument.sh
Created December 2, 2019 21:53
To reference the last argument passed to a script
args=$# # Number of args passed.
lastarg=${!args}
# or:
# lastarg=${!#}
echo $lastarg
@junhan-z
junhan-z / retrive_oui_phantom.js
Last active May 19, 2020 06:26
Use PhantomJS to Log in to IEEE
var page = require('webpage').create();
page.onConsoleMessage = function(msg) {
console.log(msg);
};
var ieeeSignInUrl = "https://regauth.standards.ieee.org/standards-ra-web/rest/signin";
page.open(ieeeSignInUrl, function(status) {
if ( status === "success" ) {