Skip to content

Instantly share code, notes, and snippets.

View yingray's full-sized avatar
:octocat:

Ray Lu yingray

:octocat:
View GitHub Profile
@yingray
yingray / form-submit.ts
Last active November 23, 2022 07:05
Form submit in Typescript
type TFormSubmitOptions = {
body?: { [key: string]: any };
method?: string;
};
const formSubmit = (endpoint: string, options?: TFormSubmitOptions) => {
const { body = {}, method = 'POST' } = options || {};
const form = document.createElement('form');
form.setAttribute('method', method);
@yingray
yingray / debounce.js
Last active February 18, 2022 08:42
Implement debounce and throttle
const input = document.getElementById("input");
function debounce(eventListener, msec) {
let timer
return (...args) => {
clearTimeout(timer);
timer = setTimeout(() => {
clearTimeout(timer);
timer = null;
eventListener.call(this, ...args); // eventListener(...args) x
@yingray
yingray / 00_Kubernetes Setup a Local Development Environment.md
Last active August 1, 2019 06:06
[Kubernetes] Setup a Local Development Environment

[Kubernetes] Setup a Local Development Environment

@yingray
yingray / helm-service-account.yaml
Last active July 31, 2019 05:41
Quickly initialize Helm Tiller for GKE
# Create a service account for Helm and grant the cluster admin role.
# It is assumed that helm should be installed with this service account
# (tiller).
apiVersion: v1
kind: ServiceAccount
metadata:
name: tiller
namespace: kube-system
---
apiVersion: rbac.authorization.k8s.io/v1
#!/usr/bin/env zsh
#local return_code="%(?..%{$fg[red]%}%? ↵%{$reset_color%})"
setopt promptsubst
autoload -U add-zsh-hook
PROMPT_SUCCESS_COLOR=$FG[117]
PROMPT_FAILURE_COLOR=$FG[124]
PROMPT_VCS_INFO_COLOR=$FG[242]
@yingray
yingray / paginateRef.js
Last active March 7, 2019 16:43
Firebase ref with pagination for firebase-server
// obj === parsed.d.b.q
const paginateRef = (ref, obj = {}) => {
Object.entries(obj).forEach(([key, value]) => {
switch (key) {
case "sp": {
ref = ref.startAt(value);
break;
}
case "ep": {
ref = ref.endAt(value);
@yingray
yingray / index.js
Created November 21, 2018 06:25
Nodejs: aes-256-cbc examples (with iv, blockSize)
import crypto from "crypto";
const algorithm = "aes-256-cbc";
const Aes256 = (text, key, iv) => {
let cipher = crypto.createCipheriv(algorithm, new Buffer.from(key), new Buffer.from(iv));
cipher.setAutoPadding(false);
let encrypted = cipher.update(PKCS5Padding(text));
encrypted = Buffer.concat([encrypted]);
return encrypted.toString("hex");
@yingray
yingray / main.go
Last active February 6, 2024 08:27
Golang: aes-256-cbc examples (with iv, blockSize)
package main
import (
"bytes"
"crypto/aes"
"crypto/cipher"
"encoding/hex"
"fmt"
)
@yingray
yingray / android_instructions.md
Created April 12, 2018 05:35 — forked from patrickhammond/android_instructions.md
Easily setup an Android development environment on a Mac

Here is a high level overview for what you need to do to get most of an Android environment setup and maintained.

Prerequisites (for Homebrew at a minimum, lots of other tools need these too):

  • XCode is installed (via the App Store)
  • XCode command line tools are installed (xcode-select --install will prompt up a dialog)
  • Java

Install Homebrew:

ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"

@yingray
yingray / .zshrc
Last active July 28, 2018 01:06
[2018.4] Terminal Configuration - Macbook pro 15"
# If you come from bash you might have to change your $PATH.
# export PATH=$HOME/bin:/usr/local/bin:$PATH
# Path to your oh-my-zsh installation.
export ZSH=/Users/yingray_lu/.oh-my-zsh
# Set name of the theme to load. Optionally, if you set this to "random"
# it'll load a random theme each time that oh-my-zsh is loaded.
# See https://github.com/robbyrussell/oh-my-zsh/wiki/Themes
ZSH_THEME="agnoster"