Skip to content

Instantly share code, notes, and snippets.

View KevCui's full-sized avatar
🖤

K̶e̶v̶i̶n̶ KevCui

🖤
View GitHub Profile
@KevCui
KevCui / script-in-html.js
Created December 3, 2017 15:05
Post: Ship PWA Guided by Lighthouse
if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('./sw.js')
.then(function(registration) {
console.log("Service Worker Registered", registration);
})
.catch(function(err) {
console.log("Service Worker Failed to Register", err);
})
}
@KevCui
KevCui / 9gag.py
Created December 10, 2017 14:23
Open 9GAG NSFW image link without login
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Open 9GAG NSFW image link without login
# How to use: 9gag.py "<url>"
import webbrowser
import sys, re
m = re.search('\/\w{7}', sys.argv[1])
link = "http://img-9gag-lol.9cache.com/photo" + m.group(0) + "_460s.jpg"
print(link)
webbrowser.open(link)
@KevCui
KevCui / update-tridactyl-conf.sh
Last active July 25, 2021 11:26
A script applies Tridactyl configuration in seconds
#!/bin/bash
# Never heard of Tridctyl? Check this out https://addons.mozilla.org/en-US/firefox/addon/tridactyl-vim/
# This script can apply Tridactyl configuration in seconds:
# Step 1: Modify key bindings and string value in the variable "data" as json format.
# Step 2: ./update-tridactyl-conf.sh <path/storage-sync-v2.sqlite>
if [[ -z $(command -v sqlite3) ]]; then
echo "Command \"sqlite3\" does not exist!"
echo "Downlad: https://sqlite.org/download.html"
exit 1
@KevCui
KevCui / commandline-dark.css
Created December 12, 2017 20:44
Tridactyl dark theme
body {
overflow: hidden;
margin: 0;
}
input {
width: 100%;
padding: 0;
font-family: monospace;
font-size: 9pt;
@KevCui
KevCui / hint-dark.css
Created December 12, 2017 21:26
Tridactyl dark theme
span.TridactylHint {
position: absolute;
font-family: sans-serif;
font-size: 12px;
font-weight: bold;
text-transform: uppercase;
color: white;
background-color: #204e8a;
border-color: ButtonShadow;
border-width: 0px;
@KevCui
KevCui / jwtDecoder.sh
Last active September 7, 2020 09:08
A Bash script to decode JWT token
#!/usr/bin/env bash
# HOW TO USE:
# ~$ chmod +x jwtDecoder.sh
# ~$ ./jwtDecoder.sh "<JWT token>"
padding() {
# $1: base64 string
local m p=""
m=$(( ${#1} % 4 ))
[[ "$m" == 2 ]] && p="=="
body { background: #222; color: #e6e6e6; }
a { color: #949494; }
a:link, a:visited { color: #949494; }
a:hover, a:active, a:focus { color: #c7c7c7; }
hr { border-bottom: 1px solid #424242; border-top: 1px solid #222; }
@KevCui
KevCui / calibrecli.sh
Last active July 13, 2019 16:25
Send ebook to Kindle using Calibre CLI tools
#!/usr/bin/env bash
#
#/ This scrip will send selected ebook to device
#/ Go to ebook folder created by calibre and run this script
#/
#/ Usage:
#/ ./calibrecli.sh "<ebook_file>" "<device_path>"
set -e
set -u
@KevCui
KevCui / nCoVstatus.sh
Created February 5, 2020 07:55
Show Coronavirus 2019-nCoV global status in terminal
#!/usr/bin/env bash
# Data fetched from the dashboard "Coronavirus 2019-nCoV Global Cases" https://gisanddata.maps.arcgis.com/apps/opsdashboard/index.html#/bda7594740fd40299423467b48e9ecf6
echo "Country/Region: Confirmed / Deaths / Recovered"
curl -sS 'https://services1.arcgis.com/0MSEUqKaxRlEPj5g/arcgis/rest/services/ncov_cases/FeatureServer/2/query?f=json&where=1%3D1&returnGeometry=false&spatialRel=esriSpatialRelIntersects&outFields=*&orderByFields=Confirmed%20desc&resultOffset=0&resultRecordCount=250&cacheHint=true' | jq -r '.features[].attributes | "\(.Country_Region)+\(.Confirmed)+\(.Deaths)+\(.Recovered)"' | column -t -s '+'
echo -e "\n"
curl -sS 'https://services1.arcgis.com/0MSEUqKaxRlEPj5g/arcgis/rest/services/ncov_cases/FeatureServer/1/query?f=json&where=1%3D1&returnGeometry=false&spatialRel=esriSpatialRelIntersects&outFields=*&outStatistics=%5B%7B%22statisticType%22%3A%22sum%22%2C%22onStatisticField%22%3A%22Confirmed%22%2C%22outStatisticFieldName%22%3A%22value%22%7D%5D&cacheHint=true' | jq -r '"
@KevCui
KevCui / 1to50.js
Created April 13, 2020 12:24
Complete 1to50 challenge with puppeteer https://twitter.com/fltoledo/status/1248789014632476672
const puppeteer = require('puppeteer-core');
(async() => {
const cPath = '/usr/bin/chromium';
const isHeadless = true;
const url = 'http://zzzscore.com/1to50/en';
const browser = await puppeteer.launch({executablePath: cPath, headless: isHeadless});
const page = await browser.newPage();
await page.goto(url, {timeout: 30000, waitUntil: 'domcontentloaded'});