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 / 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
@royling
royling / background.js
Last active November 13, 2024 15:15
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 / 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 &&
/*
* 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 / 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
@royling
royling / note.md
Last active April 21, 2017 13:34
Mixins vs. subclass in JavaScript
@royling
royling / git.sh
Created March 23, 2017 04:04
git autocomplete
wget https://raw.githubusercontent.com/git/git/master/contrib/completion/git-completion.bash
# add to .bashrc
source ~/git-completion.bash
@royling
royling / ngmodule.md
Last active March 21, 2017 09:45
NgModule pitfalls

http://blog.angular-university.io/angular2-ngmodule/

Modules are very useful, but beware of the following pitfalls:

  • do not redeclare a component, directive, etc. in more than one module
  • modules do not create their own DI context, so injectables are available also outside the module
  • unless the module is lazy loaded, in that case a separate DI context is created by the router to avoid accidental injectable overrides and prevent hard to troubleshoot bugs >- if you have a shared module that needs to be added to a lazy loaded module, make sure that it does not have providers, because that would create duplicate service instances (unless that is the intended behavior)
@royling
royling / 1-sync-vs-async.md
Last active June 7, 2024 08:01
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 / d1.js
Last active December 26, 2016 12:41
Advent of Code 2016 - http://adventofcode.com/2016
const parseInput = input => input.split(', ').map(value => {
return { turn: value[0], blocks: Number(value.slice(1)) };
});
const turnToDirection = {
N: { L: 'W', R: 'E' },
S: { L: 'E', R: 'W' },
E: { L: 'N', R: 'S' },
W: { L: 'S', R: 'N' }
};