Skip to content

Instantly share code, notes, and snippets.

View hongbo-miao's full-sized avatar
❣️

Hongbo Miao hongbo-miao

❣️
View GitHub Profile
@dennisreimann
dennisreimann / .travis.yml
Last active September 23, 2022 16:11
Travis-CI config for Yarn 2
language: node_js
cache:
# Yarn 2 does not store dependencies in node_modules anymore, at least not by default.
# If you are using the node-modules plugin, remove the `npm: false` line.
npm: false
# Yarn 2 caches to the local .yarn directory, not the Travis default `$HOME/.yarn`
directories:
- ./.yarn/cache
@markmichon
markmichon / CircuitBreaker.js
Last active July 23, 2021 21:13
Basic CircuitBreaker Node
class CircuitBreaker {
constructor(request) {
this.request = request
this.state = "CLOSED"
this.failureThreshold = 3
this.failureCount = 0
this.successThreshold = 2
this.successCount = 0
this.timeout = 6000
this.nextAttempt = Date.now()
@lucj
lucj / k3s-multipass.sh
Created December 17, 2019 21:16
Setup a k3s kubernetes cluster using Multipass VMs
for node in node1 node2 node3;do
multipass launch -n $node
done
# Init cluster on node1
multipass exec node1 -- bash -c "curl -sfL https://get.k3s.io | sh -"
# Get node1's IP
IP=$(multipass info node1 | grep IPv4 | awk '{print $2}')
@hongbo-miao
hongbo-miao / index.js
Last active October 15, 2019 23:54
Chat
// 1. Server
// node index.js
//
// 2. Client
// 1) Start
// telnet localhost 3001
//
// 2) Quit
// Click Ctrl + ], then Ctrl + C
@y0ngb1n
y0ngb1n / docker-registry-mirrors.md
Last active June 13, 2024 07:22
国内的 Docker Hub 镜像加速器,由国内教育机构与各大云服务商提供的镜像加速服务 | Dockerized 实践 https://github.com/y0ngb1n/dockerized
@animir
animir / user.controller.ts
Last active March 2, 2024 08:28
Nest.js prevent brute-force against authorisation example
import { Request, Response } from 'express';
import { Body, Controller, Post, Req, Res } from '@nestjs/common';
import { UserService } from './user.service';
import * as Redis from 'ioredis';
import { RateLimiterRedis } from 'rate-limiter-flexible';
const redisClient = new Redis({enableOfflineQueue: false});
const maxWrongAttemptsByIPperDay = 100;
const maxConsecutiveFailsByUsernameAndIP = 5;
@jayphelps
jayphelps / redux-observable-typescript-testing-example.ts
Created February 24, 2019 05:33
Example using redux-observable + typescript + TestScheduler, with a run helper written
import { map, delay } from 'rxjs/operators';
import { TestScheduler } from 'rxjs/testing';
import { Action } from 'redux';
import { Epic, ofType, ActionsObservable, StateObservable } from 'redux-observable';
const scheduler = new TestScheduler((actual, expected) => {
if (JSON.stringify(actual) !== JSON.stringify(expected)) {
throw new Error(`Failing test
actual: ${JSON.stringify(actual, null, 2)}
@bvaughn
bvaughn / index.md
Last active June 12, 2024 12:59
How to use profiling in production mode for react-dom

React recently introduced an experimental profiler API. This page gives instructions on how to use this API in a production release of your app.

Table of Contents

Profiling in production

React DOM automatically supports profiling in development mode for v16.5+, but since profiling adds some small additional overhead it is opt-in for production mode. This gist explains how to opt-in.

@bvaughn
bvaughn / index.md
Last active April 3, 2024 07:41
Interaction tracing with React

This API was removed in React 17


Interaction tracing with React

React recently introduced an experimental profiler API. After discussing this API with several teams at Facebook, one common piece of feedback was that the performance information would be more useful if it could be associated with the events that caused the application to render (e.g. button click, XHR response). Tracing these events (or "interactions") would enable more powerful tooling to be built around the timing information, capable of answering questions like "What caused this really slow commit?" or "How long does it typically take for this interaction to update the DOM?".

With version 16.4.3, React added experimental support for this tracing by way of a new NPM package, scheduler. However the public API for this package is not yet finalized and will likely change with upcoming minor releases, so it should be used with caution.

@SeppPenner
SeppPenner / Installing Python 3.7.4 on Raspbian.rst
Last active May 9, 2024 21:52
Installing Python 3.7.4 on Raspbian

Installing Python 3.7.4 on Raspbian

As of July 2018, Raspbian does not yet include the latest Python release, Python 3.7.4. This means we will have to build it ourselves, and here is how to do it.

  1. Install the required build-tools (some might already be installed on your system).