Skip to content

Instantly share code, notes, and snippets.

View WanLinLin's full-sized avatar

Wanlin Lin WanLinLin

  • foodpanda
  • Taipei, Taiwan
View GitHub Profile
@WanLinLin
WanLinLin / get-keys-in-ci.sh
Created August 2, 2022 09:06
get keys in CI
### in local ###
# gen private key
openssl genrsa -aes128 -out private.pem 4096
# gen public key from private key
openssl rsa -in private.pem -pubout > public.pem
### in CI ###
# setup the $PUB secret in the CI platform settings, create public key in CI steps
echo "$PUB" > public.pem
# list ingress host and paths, ref https://www.kaper.com/cloud/find-kubernetes-ingress-rules/
kubectl get ingress -o json | \
jq -r '.items[] | . as $parent | .spec.rules[] | select(.host=="HOST.NAME.YOU.WANT") | .host as $host | .http.paths[] | ( $host + " " + .path + " " + .backend.service.name + " " + $parent.metadata.name )' | \
sort
@WanLinLin
WanLinLin / rebase.sh
Created July 21, 2022 08:51
rebase.sh $target_branch $root_commit_hash
cur_branch=$(git branch --show-current)
git checkout $1
git pull
git checkout $cur_branch
git rebase --onto $1 $2
@WanLinLin
WanLinLin / prune-local-branches.sh
Created July 20, 2022 08:06
Prune local branches that is pruned remotely
remote_pruned_branches=$(git remote prune origin | tail -n +3 | sed -e 's| \* \[pruned\] origin/||')
echo "remote pruned branches:\n$remote_pruned_branches"
echo "\ndeleting branches:"
echo $remote_pruned_branches | xargs git branch -D
@WanLinLin
WanLinLin / sourcemap-help.js
Last active February 20, 2024 01:30
Find source position from minified stack trace
const sourceMap = require("source-map");
const fetch = require('node-fetch');
const sourcemapUrl = 'https://example.com/9fb743af.chunk.js.map';
const targetLine = 6;
const targetColumn = 9497;
fetch(sourcemapUrl)
.then(body => body.text())
.then(map => new sourceMap.SourceMapConsumer(map))
@WanLinLin
WanLinLin / google-ad-manager-ad-unit.jsx
Last active July 5, 2020 02:44
Google Ad Manager Ad Unit React Component
import React from 'react'
import PropTypes from 'prop-types'
const GOOGLE_AD_MANAGER_ID = 'YOUR_ID'
/**
* It's used to generate ad element id. Make sure:
* - only increment it ONCE per component
* - only modify it on browser, not on server side
*/
@WanLinLin
WanLinLin / index.html
Last active July 5, 2020 02:28
Recaptcha React Component
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>React Recaptcha Example</title>
</head>
<body>
<script>
function onRecaptchaLoaded() {
@WanLinLin
WanLinLin / append_query_to_url.py
Created June 20, 2019 07:11
Merge query to url (python 2.7.13)
import urlparse
def merge_query_to_url(url, query):
"""Merge query into url without any url encode/decode."""
url_parts = urlparse.urlparse(url)
# convert existing query string to dict
#
# Not using `urlparse.parse_qs` to extract existing query from url because
# it will convert url's query to utf8 string if it's url encoded