Skip to content

Instantly share code, notes, and snippets.

View shenjunru's full-sized avatar

Shen Junru shenjunru

View GitHub Profile
/**
@class BroadcastChannel
A simple BroadcastChannel polyfill that works with all major browsers.
Please refer to the official MDN documentation of the Broadcast Channel API.
@see <a href="https://developer.mozilla.org/en-US/docs/Web/API/Broadcast_Channel_API">Broadcast Channel API on MDN</a>
@author Alessandro Piana
@version 1.0.0
*/
/*
@shenjunru
shenjunru / RSAUtils.java
Last active September 24, 2022 01:16
RSA key parser in JAVA
/**
* Parse private or public key in PKCS#1 or PKCS#8 format
* No 3rd-party library required
*/
import java.nio.charset.Charset;
import java.security.KeyFactory;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.security.spec.PKCS8EncodedKeySpec;

Everything I Know About UI Routing

Definitions

  1. Location - The location of the application. Usually just a URL, but the location can contain multiple pieces of information that can be used by an app
    1. pathname - The "file/directory" portion of the URL, like invoices/123
    2. search - The stuff after ? in a URL like /assignments?showGrades=1.
    3. query - A parsed version of search, usually an object but not a standard browser feature.
    4. hash - The # portion of the URL. This is not available to servers in request.url so its client only. By default it means which part of the page the user should be scrolled to, but developers use it for various things.
    5. state - Object associated with a location. Think of it like a hidden URL query. It's state you want to keep with a specific location, but you don't want it to be visible in the URL.
@shenjunru
shenjunru / routeros-ddns-dnspod.sh
Created January 13, 2020 14:21
DNSPod DDNS Updater on RouterOS
#policy: read,test
#pppoe-interface
:local pppoe "pppoe-out1"
#dnspod-token
:local token "uid,api-toekn"
#dnspod-domain
:local domain "example.com"
@shenjunru
shenjunru / download-realm.sh
Last active March 5, 2019 14:54
download-realm.sh
#!/bin/sh
# file: node_modules/realm/scripts/download-realm.sh
# cwd: node_modules/realm
cd "$(dirname $0)/.."
source ./dependencies.list
VENDOR_DIR="vendor"
LOCKFILE_NAME="download-realm.lock"
NEW_CORE_SERVER_FOLDER="core/v${REALM_CORE_VERSION}"
@shenjunru
shenjunru / node-fs-remove.js
Created May 7, 2018 05:17
node.js remove directory recursively
// remove directory recursively
const { promisify } = require('util');
const $fsys = require('fs');
const $path = require('path');
const fstat = promisify($fsys.stat);
const lsdir = promisify($fsys.readdir);
const mkdir = promisify($fsys.mkdir);
const rmdir = promisify($fsys.rmdir);
const unlink = promisify($fsys.unlink);
// https://www.textnow.com
// https://www.google.com/voice/?setup=1#setup/
// node >= 8
// usage: node script.js "curl ..."
const https = require('https');
const http = require('http');
const zlib = require('zlib');
const { URL } = require('url');
@shenjunru
shenjunru / keybase.md
Created March 4, 2017 13:33
keybase.md

Keybase proof

I hereby claim:

  • I am shenjunru on github.
  • I am shenjunru (https://keybase.io/shenjunru) on keybase.
  • I have a public key whose fingerprint is E3F1 148D 82A1 007E 9266 FDAD 5B97 70CD 0A18 0E3B

To claim this, I am signing this object:

@kangax's ES6 quiz, explained

@kangax created a new interesting quiz, this time devoted to ES6 (aka ES2015). I found this quiz very interesting and quite hard (made myself 3 mistakes on first pass).

Here we go with the explanations:

Question 1:
(function(x, f = () =&gt; x) {
* {
font-size: 12pt;
font-family: monospace;
font-weight: normal;
font-style: normal;
text-decoration: none;
color: black;
cursor: default;
}