Skip to content

Instantly share code, notes, and snippets.

🥋
still alive (as of 2019-10)

Wang Guan jokester

🥋
still alive (as of 2019-10)
Block or report user

Report or block jokester

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@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
View curl-speed-test.sh
#!/usr/bin/env bash
set -u
if [[ 0 -eq "$#" ]]; then
echo "Test ttfb and stuff of GET request"
echo " USAGE: $0 URL+"
exit 1
fi
@jokester
jokester / FlatListWithRefreshControl.tsx
Last active May 27, 2018
add RefreshControl to FlatList / SectionList in a simpler way
View FlatListWithRefreshControl.tsx
import * as React from 'react';
import { FlatList, FlatListProps, ScrollView, SectionList, SectionListProps } from 'react-native';
import { Debug } from "../../../util";
export function FlatListWithRefreshControl(props: FlatListProps<any>) {
const { refreshControl, renderScrollComponent: providedComponent, ...rest } = props;
Debug.assert(refreshControl && !providedComponent, 'only use this when you need to fix refreshControl');
const renderScrollComponent = (props: {}) => <ScrollView refreshControl={refreshControl} {...props} />;
@jokester
jokester / android-screenshot.sh
Created May 22, 2018
capture screenshot with adb && pull from pc
View android-screenshot.sh
#!/usr/bin/env bash
set -ue
set -o pipefail
temp_basename="screenshot-$(date '+%Y%m%d-%H%M%S-%N').png"
temp_remote="/sdcard/$temp_basename"
temp_local="/tmp/$temp_basename"
(
adb shell screencap -p "$temp_remote"
adb pull "$temp_remote" "$temp_local"
You can’t perform that action at this time.