Skip to content

Instantly share code, notes, and snippets.

View RickWong's full-sized avatar

Rick Wong RickWong

  • Amsterdam
  • 05:36 (UTC +02:00)
  • X @ryguw
View GitHub Profile
@RickWong
RickWong / InMemoryCounter.js
Last active June 8, 2018 13:18
InMemoryCounter
class InMemoryCounter {
constructor({ seconds = 1, rolling = true, max }) {
this.seconds = seconds;
this.rolling = rolling;
this.max = max;
if (!this.rolling) {
this.interval = setInterval(() => {
this.counter = 0;
}, this.seconds * 1000);
@RickWong
RickWong / rikkert.express.js
Last active June 6, 2018 08:51
Rikkert Framework
const { listen, emit } = require("rikkert");
const express = require('express');
const app = express();
const rikkertMiddleware = (req, res, next) => {
emit("http.request", { req, res }).then(next);
};
app.use(rikkertMiddleware);
app.listen(3000);
@RickWong
RickWong / µredux.es6
Last active August 25, 2016 10:15 — forked from rstacruz/µredux.js
Redux in <1kb
const INIT = '@redux/INIT';
export const createStore = (reducer, state, enhancer) => {
if (enhancer) {
return enhancer(createStore)(reducer, state);
}
const subscribers = [];
dispatch({ type: INIT });
@RickWong
RickWong / blockchain.py
Created May 19, 2016 21:09 — forked from dela3499/blockchain.py
Implementation of simple blockchain
import numpy as np
import hashlib
def create_block(parent_block, value, hashfunc):
""" ------------------------------------------------
String -> Block -> (Block -> String) -> Block
------------------------------------------------
Produce a new block from a string value and a hash
of its parent block. In this case, a block is also a string.
"""
@RickWong
RickWong / react.html
Last active April 20, 2021 15:48
Write React apps in 1 HTML file.
<html>
<body>
<div id="react-root"></div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react-with-addons.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react-dom.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/redux/3.5.2/redux.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/babel-standalone/6.7.7/babel.min.js"></script>
<script id="react-app" type="text/template">
const App = ({name}) => {
@RickWong
RickWong / app.js
Last active December 22, 2020 13:37
React without Webpack
const App = ({name}) => {
return (
<h1>Hello {name}</h1>
);
};
ReactDOM.render(<App name="World" />, document.getElementById("App"));
@RickWong
RickWong / decorate.js
Created August 8, 2015 10:08
ES6 function decorators
function decorate (...functions) {
return functions.reduce(
(a, b) => b(a),
functions.pop() // Pop wrapped function as initial value
);
};
decorate(
(func) => (text) => func(text.toUpperCase() + "!"), // Outer-wrapper