Skip to content

Instantly share code, notes, and snippets.

View bearzk's full-sized avatar

Kai Zhang bearzk

View GitHub Profile
@bearzk
bearzk / pluralsight-curriculum.md
Created October 3, 2022 13:46
A list of pluralsight courses to get a developer ready for backend tasks in alyne

Summary of design principles

  1. Complexity is incremental: you have to sweat the small stuff (see p. 11).

  2. Working code isn't enough (see p. 14).

  3. Make continual small investments to improve system design (see p. 15).

  4. Modules should be deep (see p. 22)

@bearzk
bearzk / generate-presigned-url-with-aws-sdk-v3.js
Created January 26, 2022 21:34
an simple example script for generating presigned url with aws-sdk v3
// system imports
// 3rd party imports
const { getSignedUrl } = require('@aws-sdk/s3-request-presigner')
const { S3Client, GetObjectCommand } = require('@aws-sdk/client-s3')
// local imports
const client = new S3Client({
region: 'eu-west-1', // region, since s3 is global, guess it doesn't really matter :)
credentials: { // this credential should have read access to the bucket/object you want to grant temp access to the user
accessKeyId: 'AKIAIOSFODNN7EXAMPLE',
@bearzk
bearzk / tools.md
Last active July 2, 2024 12:40
some tools

Tools

desktop tools

Alfred

  • pastebin history
  • tldr
  • global snippets
  • ip
@bearzk
bearzk / tech-academy-2021-01.md
Created February 19, 2021 13:11
Tech Academy Session 2021 #01

Tech Academy Session 2021 #01

Code Smells 01/??

nested conditions, long condition block

I have to hold my breath for too long, maybe not so good for my health.

if (a) {
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
const exponentialBackOff = async (func, maxRetry, delay) => {
let res = await func();
if (res) {
return res;
}
console.log(`retrying, maxRetry ${maxRetry}`);
@bearzk
bearzk / proxy.js
Created February 26, 2020 08:50
[proxy] #js
/* eslint-disable max-classes-per-file */
class Repo {
constructor() {
this.name = 'maomao';
}
work(p1, p2) {
return (p1 + p2);
}
@bearzk
bearzk / lintStaged.sh
Last active March 3, 2020 11:26
[lintStaged] #bash #lint
#!/bin/sh
# this script will run eslint against staged files
# in staged flies
# find (M)odified and (A)dded file names,
# find those conotains "src" or "test"
toLint=$(git diff --name-status --cached | grep -E "^[M|A]" | awk '{print $2}' | grep -E "src|test")
if [ -z "$toLint" ]; then
@bearzk
bearzk / grepPattern.sh
Last active March 3, 2020 11:28
[grepPattern.sh] sh script to catch pattern in staged file #bash #git
#!/bin/sh
# this script will look into current staged (about to be commited) files
# searching for the pattern from $1
# if found, would exit with error status code 1
# Usage:
# when staged files contain the search pattern 'TEST'
#
# > ./grepPattern.sh TEST
@bearzk
bearzk / queue-based-load-leveling-pattern.md
Last active February 12, 2019 13:13
[Queue-Based Load Leveling pattern] #cloud #designpattern

Queue-Based Load Leveling pattern

Why and When?

Sometimes a part of our application just can not run that fast, it could be for example, avatar processing, email sending, and in these case we don't usually need a response/confirmation that the action is finished, we can push these tasks into queue and handle them asynchronously to take the load off the system.

How?

  • push slow tasks into queue