Skip to content

Instantly share code, notes, and snippets.

View royling's full-sized avatar
🔬
Keep practicing and learning everyday!

Roy Ling royling

🔬
Keep practicing and learning everyday!
View GitHub Profile
@royling
royling / 1-sync-vs-async.md
Last active May 3, 2024 06:30
RxJS5: sync vs. async observables

Sync observables created from a synchronous source will emit values synchronously, so the observers will receive values in the order of subscription.

The source iterable is traversed for each observer subscribed. For example, the size of source iterable is M, there are N observers, so the traversal times is M*N. This is explained in RxJS5 Manual:

Plain Observables are unicast (each subscribed Observer owns an independent execution of the Observable)

let sub = Rx.Observable.range(0, 3);

sub.subscribe(value => console.log(`observer 1: ${value}`));
sub.subscribe(value => console.log(`observer 2: ${value}`));
@royling
royling / background.js
Last active March 10, 2024 14:04
Click Chrome extension icon to execute scripts on active tab
chrome.action.onClicked.addListener((tab) => {
chrome.scripting.executeScript({
target: {
tabId: tab.id,
},
files: ["content.js"],
});
});
@royling
royling / tmux-iterm2.md
Last active April 24, 2023 19:35
tmux in iTerm2 cheatsheet
@royling
royling / proceed.js
Created March 5, 2021 07:02
Proceed
// Copy and save the script as a predefined snippet in Chrome Devtools
// Run it to proceed to an insecured website if blocked by Chrome
// See how to use snippets: https://developers.google.com/web/tools/chrome-devtools/javascript/snippets
(function() {
const link = document.querySelector('#proceed-link');
if (link && link.tagName.toLowerCase() === 'a') {
link.click();
} else if (
typeof sendCommand === "function" &&
SecurityInterstitialCommandId &&
@royling
royling / gitr
Last active October 7, 2021 12:35
run git command in multiple repositories
#! /bin/bash
CWD=`pwd`
printUsage() {
echo "gitr - Git for multiple repositories made easy!"
echo -e "Usage: gitr <branch|status|push|pull|fetch|merge|stash|checkout [options] [arguments]> [--repos <repo>...] [--gitr-base <path>]"
}
println() {
echo "$1"
@royling
royling / webdriver-manager.md
Last active September 21, 2021 21:23
UNABLE_TO_GET_ISSUER_CERT_LOCALLY/"Error: unable to get local issuer certificate" with `webdriver-manager update`

With angular-cli, it helps create an angular2 app quickly. All required tools are provisioned in a simple command ng new, including Protractor - the end-to-end testing tool for angular.

To perform the testing, run ng e2e. It will first run webdriver-manager update to download & install webdrivers, see pree2e script in package.json. However, the below error may be encountered if you are in a corporate network:

[15:10:59] E/downloader - { Error: unable to get local issuer certificate
    at Error (native)
    at TLSSocket.<anonymous> (_tls_wrap.js:1060:38)
    at emitNone (events.js:86:13)
 at TLSSocket.emit (events.js:185:7)
@royling
royling / fibonacci.go
Last active April 24, 2021 14:51
go tour exercises
package main
import "fmt"
// fibonacci is a function that returns
// a function that returns an int.
func fibonacci() func() int {
a, b := 0, 1
return func() int {
i := a
/*
* Copyright 2002-2012 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@royling
royling / interweave.js
Last active February 25, 2018 13:49
Interweave arrays
// inspired when reading https://leanpub.com/understandinges6/read#leanpub-auto-define-tags
// this is the behavior that template tags may interweave literals and subsitutions arrays
var interweave = (a, b) => {
let min = Math.min(a.length, b.length);
return Array.apply(null, Array(min)).reduce((result, value, index) => {
result.push(a[index], b[index]);
return result;
}, []).concat((a.length > min ? a : b).slice(min));
};
@royling
royling / anyconnect.sh
Last active January 14, 2018 10:21
AnyConnect CLI on macOS
#!/bin/sh
USERNAME=user_name
HOST=vpn.example.com
vpn=/opt/cisco/anyconnect/bin/vpn
case "$1" in
connect )
shift