Skip to content

Instantly share code, notes, and snippets.

View guanzo's full-sized avatar
💭
Remember the Cant

Eric Guan guanzo

💭
Remember the Cant
View GitHub Profile
@guanzo
guanzo / sub.ts
Last active November 30, 2023 19:16
const res = await stripe.subscriptions.update(subscriptions[0].id, {
default_payment_method: paymentMethods[0].id,
billing_cycle_anchor: 'unchanged',
proration_behavior:'always_invoice',
items: [
...subscriptions[0].items.data.map((item) => ({
id: item.id,
deleted: true,
clear_usage:
item.plan.usage_type === 'metered' ? true : undefined,
@guanzo
guanzo / kucoin.js
Last active October 7, 2023 05:15
Set Kucoin Trading View Time Period
// ==UserScript==
// @name Set Kucoin Trading View Time Period
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author You
// @match https://www.kucoin.com/trade/*
// @exclude https://www.kucoin.com/trade/charting_library*
// @icon https://www.google.com/s2/favicons?sz=64&domain=kucoin.com
// @grant none
@guanzo
guanzo / main.go
Last active May 16, 2023 06:13
go http1 vs http2 benchmark
package main
import (
"crypto/tls"
"flag"
"fmt"
"io/ioutil"
_ "io/ioutil"
"math/rand"
"net/http"

Usage

txns = getBlockTxns(block=100)
txn = txns[0]

sender = TxnFields.sender(txn)
gid = TxnFields.group(txn)
appId = TxnFields.appId(txn)
innerTxns = TxnFields.innerTxns(txn)
const sleep = ms => new Promise(resolve => setTimeout(resolve, ms))
// Modified from https://github.com/wmcmurray/just-detect-adblock
// Detects: uBlock, Adblock, Adblock Plus, AdBlocker Ultimate, Ghostery,
export async function isAdblockDetected () {
let detected = false
// create the bait
const bait = document.createElement('div')
@guanzo
guanzo / idgaf-local-storage.js
Last active April 30, 2020 11:02
localStorage API that swallows errors.
// https://developer.mozilla.org/en-US/docs/Web/API/Storage
// Wraps all methods in a try/catch.
// Useful for non-critical storage, and when swallowing errors is acceptable.
// Reasons why localStorage might fail:
// * Simply referencing window.localStorage when in a 3rd party iframe. (brave & safari)
// * localStorage can be null
// * Storage quota exceeded
const methods = ['key', 'getItem', 'setItem', 'removeItem', 'clear']
const idgafLocalStorage = {}

In real code, you would call makePromise().then() or await makePromise(). I assigned the promise to an intermediate variable to illustrate the difference. Which style do you prefer?

const cl = console.log

function thenCatch () {
    cl('start')
    
    const promise = makePromise()

Async calls

<template>
<!-- 
When isLoading is true, the <div> is in the DOM, the <p> is not.
When isLoading is false, Vue will remove the <div> and add the <p> to the DOM,
at which point <MyComponent> will be created and passed the fetched data.
-->
apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
annotations:
helm.sh/hook: crd-install
creationTimestamp: "2019-06-04T20:20:40Z"
generation: 1
name: federatedsecrets.types.kubefed.k8s.io
resourceVersion: "5492"
selfLink: /apis/apiextensions.k8s.io/v1beta1/customresourcedefinitions/federatedsecrets.types.kubefed.k8s.io
@guanzo
guanzo / .block
Last active April 26, 2020 14:37
D3 Show Reel - Hierarchies
license: gpl-3.0
height: 700