Skip to content

Instantly share code, notes, and snippets.

View Weiyuan-Lane's full-sized avatar
🐈
Code. Code! CODE! CODE!!!!!!

Weiyuan Liu Weiyuan-Lane

🐈
Code. Code! CODE! CODE!!!!!!
View GitHub Profile
@Weiyuan-Lane
Weiyuan-Lane / manifest.json
Created January 20, 2019 14:51
Chrome Extension Manifest Example
{
"name": "Staff App",
"description": "Internal buttons and controls only for staff",
"author": "Weiyuan Liu",
"version": "0.0.1",
"manifest_version": 1,
"background": {
"scripts" : [
"build/browser-action.js",
"build/context-menu.js"
@Weiyuan-Lane
Weiyuan-Lane / MenuItem.js
Created January 20, 2019 15:58
MenuItem entity for context menu to make nesting menu items as modules in modules.
'use strict'
/* This is a global variable containing all the
* callbacks for various menu items
*
* In the following line, a listener is attached
* to the contextMenus onClicked API, where an id
* is inputted to identify the callback to trigger
* with the registered callbacks
*/
@Weiyuan-Lane
Weiyuan-Lane / RootMenuItem.js
Last active January 20, 2019 16:14
Root menu item implementation modularized with MenuItem
'use strict'
import CONSTANTS from 'scripts/constants/Constants'
import MenuItem from 'scripts/context-menus/MenuItem'
// The following contains other menu items created and exported in their own files
// They too will either contain a callback or even more child menu items
import PreviewPageMenuItem from 'scripts/context-menus/PreviewPageMenuItem'
import EditPageMenuItem from 'scripts/context-menus/EditPageMenuItem'
import ForumsMenuItem from 'scripts/context-menus/ForumsMenuItem'
import Separator from 'scripts/context-menus/Separator' // This is a factory for creating menu items that functions as separator
@Weiyuan-Lane
Weiyuan-Lane / context-menu.js
Created January 20, 2019 16:11
context-menu.js initialisation script
'use strict'
import RootMenuItem from 'scripts/context-menus/RootMenuItem'
// Initialisation when run
RootMenuItem.init()
@Weiyuan-Lane
Weiyuan-Lane / browser-action.js
Created January 20, 2019 16:24
Logic concerning the browser-action icon.
'use-strict'
import CONSTANTS from 'scripts/constants/Constants'
function updateIconWith({ tabId, url }){
if(url && url.match(CONSTANTS.BROWSER_ICON_URL_REGEX)){
chrome.browserAction.setIcon({ path: 'public/images/logos/staff-32.png', tabId: tabId});
} else {
chrome.browserAction.setIcon({ path: 'public/images/logos/staff-32-faded.png', tabId: tabId});
}
@Weiyuan-Lane
Weiyuan-Lane / gokitexample.go
Last active February 1, 2019 17:37
Proposed Go kit usage across different protocols
package example
import (
"context"
"google.golang.org/grpc"
"github.com/gorilla/mux"
"github.com/go-kit/kit/endpoint"
"github.com/exampleproject/httplogic"
"github.com/exampleproject/grpclogic"
gs "github.com/exampleproject/grpcschema"
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
labels:
app: nginx
spec:
replicas: 3 # This can be changed any time as config and pods will scale up with the change
selector:
matchLabels:
@Weiyuan-Lane
Weiyuan-Lane / cluster.jinja
Created February 3, 2019 05:17
Deployment manager config example using a jinja file
{# Note that the following properties can be passed with running deployment manager #}
{# setting up deployment manager can be as simple as follows: #}
{# `gcloud deployment-manager deployments create deployment --template cluster.jinja --properties "ADD PROPERTIES FOR BELOW CONFIG HERE" ` #}
{% set CLUSTER_NAME = properties['clusterName'] %}
{% set REGION = properties['region'] %}
{% set NODE_POOL_NAME = properties['nodePoolName'] %}
{% set NODE_POOL_MIN = properties['nodePoolMinCount'] %}
@Weiyuan-Lane
Weiyuan-Lane / deferasync.html
Created February 3, 2019 05:28
Defer and async script loading example
<html>
<head></head>
<body>
<!-- Script loading, parsing and execution after html content below
is rendered, or what is known as "DOMContentLoaded" event -->
<script src="script_one.js" defer="defer"></script>
<!-- Same as above, except it maintains order of execution after
"script_one" -->
<script src="script_two.js" defer="defer"></script>
@Weiyuan-Lane
Weiyuan-Lane / progressive_plus_lazy_load_image.html
Created February 3, 2019 06:13
Showcase progressive loading + lazyloading of images
<html>
<head></head>
<body>
<!-- Using the lazysizes library, we can define a low
res image to load, and asynchronously load
a image appropriate to the user's screen size -->
<img
class="lazyload"
src="low_res.jpg"
data-src="low_res.jpg"