Skip to content

Instantly share code, notes, and snippets.

Avatar
🥋
still alive (as of 2020-12)

Wang Guan jokester

🥋
still alive (as of 2020-12)
View GitHub Profile
@jokester
jokester / some-workflow-snippet.yaml
Last active Nov 22, 2020
Tricks for github action workflows
View some-workflow-snippet.yaml
# poc of string interpolation in bash / github action
- name: print env variables to job output
run: for v in `cat env` ; do echo "::set-env name=${v%%=*}::${v##*=}" ; done
- name: use (maybe ) in shell command
run: docker push myrepo/myapp:${TAG_REF#refs/tags/}
env:
TAG_REF: ${{ github.ref }}
@jokester
jokester / converter_base.rb
Created Mar 1, 2020
my beancount importers
View converter_base.rb
module Converter
class BaseConverter
def initialize input_file, **options
@input_file = input_file
@options = options
end
def write output_file, force: false
if output_file.exist? && !force
puts " NOT overwriting #{output_file}. remove dest file and rerun or specify 'force' flag"
@jokester
jokester / 00-cloud-config.yml
Created Oct 18, 2019 — forked from janeczku/00-cloud-config.yml
Annotated RancherOS Cloud-init configuration snippets
View 00-cloud-config.yml
#cloud-config
# Set the hostname for this machine (takes precedence over hostname assigned by DHCP lease).
hostname: myhost
# Authorize SSH keys for the `rancher` sudoer user
ssh_authorized_keys:
- ssh-rsa AAA...ZZZ example1@rancher
@jokester
jokester / index.d.ts
Created Mar 15, 2019
typescript declaration of next-mui-helper
View index.d.ts
// TYPE_ROOT/next-mui-helper/index.d.ts
declare module 'next-mui-helper/nextjs/makeNextDocument' {
import { Theme } from "@material-ui/core";
const makeNextDocument: (muiTheme?: Theme) => React.Component;
export = makeNextDocument;
}
@jokester
jokester / next.config.js
Created Mar 14, 2019
disable clear of terminal in next.js 8
View next.config.js
{
// silly way to prevent next.js clearing screen
// see https://github.com/zeit/next.js/blob/41eaa9cf5ade8f233439a80f7e846ccb00ef3f18/packages/next/build/output/store.ts#L24-L25
const readline = require('readline');
readline.cursorTo = readline.clearScreenDown = () => {};
}
@jokester
jokester / next.config.js
Created Mar 14, 2019
disable clear of terminal in next.js 8
View next.config.js
{
// silly way to prevent next.js clearing screen
// see https://github.com/zeit/next.js/blob/41eaa9cf5ade8f233439a80f7e846ccb00ef3f18/packages/next/build/output/store.ts#L24-L25
const readline = require('readline');
readline.cursorTo = readline.clearScreenDown = () => {};
}
@jokester
jokester / ssr-jsr-nextjs8.md
Created Feb 22, 2019
SSR and BSR in next.js (as of 8), in a pseudecode form
View ssr-jsr-nextjs8.md

First screen: server-side rendering

happens on first navigation

  1. @server: p1 = await App.getInitialProps
    • calls Page.getInitialProps in turn
  2. @server: const html = ReactDOM.hydrate(<App { ...p1 }>);
  3. @server: res.send(html, p2 = JSON.stringify(p1)
  4. @client: parse and show html as usual
  5. @client: ReactDOM.render(<App {...JSON.parse(p2) } />)
@jokester
jokester / curl-server-cert.sh
Created Dec 27, 2018
print server certificate (for expiration check and stuff)
View curl-server-cert.sh
#!/usr/bin/env bash
set -ue
if [[ $# -eq 0 ]]; then
echo "USAGE: $0 HOST+"
echo " prints expiration date of https certs with curl"
exit 1
fi
@jokester
jokester / delay_css.py
Created Nov 7, 2018
mitmproxy: delay transfer of css response body
View delay_css.py
# usage: mitmproxy -s THIS_FILE.py
# add a delay before starting streaming response body to client
from time import sleep
from urllib.parse import urlparse
def delay_before_streaming_response(flow):
url = urlparse(flow.request.url)
if url.path.lower().endswith('.css'):
return 2