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 / CodesplittingReactLoadableExample.jsx
Created February 4, 2019 07:07
Code splitting illustrating using component splitting library, React Loadable
import React from 'react'
import Loadable from 'react-loadable'
import LoadingComponent from 'scripts/components/LoadingComponent'
class ExamplePage extends React.Component {
static Component = Loadable({
loader: () => import(/* webpackChunkName: "ExamplePage" */ 'example'),
loading: LoadingComponent, // Lightweight LoadingComponent to use whenever this component is first loaded
modules: ['ExamplePage'] // Modules to load should be accessible from loader property above
@Weiyuan-Lane
Weiyuan-Lane / base-route-spa.jsx
Last active March 10, 2019 12:05
Base application for a react-router SPA
import Navbar from 'scripts/components/Navbar'
import React, { Component } from 'react'
import { withRouter } from 'react-router'
import { renderRoutes } from 'react-router-config'
import { routes } from 'scripts/routes'
class BaseSPA extends Component {
constructor(props) {
super(props)
}
@Weiyuan-Lane
Weiyuan-Lane / dom-content-loaded-jquery-migration.html
Last active March 16, 2019 03:50
Show how a jquery $(document).ready() can be migrated to DOMContentLoaded()
<html>
<head></head>
<body>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/x.x.x/jquery.min.js" defer></script>
<script>
function initFunc(){
// Do something here for page initialisation
// For example, loading frontend SPA
}
@Weiyuan-Lane
Weiyuan-Lane / gokit_example_short.go
Last active April 4, 2019 12:29
[Shortened] Proposed go-kit usage over different protocols
package example
import (
httptransport "github.com/go-kit/kit/transport/http"
grpctransport "github.com/go-kit/kit/transport/grpc"
)
func makeCommonEndpoint() endpoint.Endpoint {
return func(ctx context.Context, request interface{}) (interface{}, error) {
// Some Logic Here
@Weiyuan-Lane
Weiyuan-Lane / simple-code.gs
Created April 14, 2019 17:20
Simple Google Apps Scripts code for testing
function alert(msg){
var ui = DocumentApp.getUi();
ui.alert(msg, ui.ButtonSet.OK);
}
function myFunction() {
alert('Hello World!');
}
@Weiyuan-Lane
Weiyuan-Lane / factorial.scss
Created June 23, 2019 09:13
Code for implementing factorial (with precomputed inputs for removing the need to repeat previous computations
@function factorial($endAt, $startAt: 1, $currentVal: 1) {
$accVal: $currentVal;
@for $i from $startAt + 1 to $endAt + 1 {
$accVal: $i * $accVal;
}
@return $accVal;
}
@Weiyuan-Lane
Weiyuan-Lane / sin.scss
Last active June 23, 2019 09:30
Function for computing sin of a input radian value
@import 'factorial';
$PI: 3.14159265358979323846;
$TWO_PI: $PI * 2;
$HALF_PI: $PI / 2;
$QUARTER_PI: $PI / 4;
$SIN_ITERATION: 10;
@function sin($rad) {
// Ensure value is between 0 to TWO_PI
@Weiyuan-Lane
Weiyuan-Lane / cos.scss
Created June 23, 2019 09:19
Function implemented for computing cos from input radian values
@import 'sin';
@function cos($rad) {
@return sin($rad + $HALF_PI);
}
@Weiyuan-Lane
Weiyuan-Lane / factorial.spec.scss
Created June 23, 2019 09:26
Unit testing sample for factorial function in SCSS
@import 'true';
@import 'factorial';
@include describe('.factorial [function]') {
@include it('should return value for 10! as 3628800') {
@include assert-equal(factorial(10), 3628800);
}
}
@include report;