Skip to content

Instantly share code, notes, and snippets.

View jokester's full-sized avatar
🌛
not my photo / still alive and with a cat now!!! (as of 2024-03)

Wang Guan jokester

🌛
not my photo / still alive and with a cat now!!! (as of 2024-03)
View GitHub Profile
@jokester
jokester / ssr-jsr-nextjs8.md
Created February 22, 2019 19:22
SSR and BSR in next.js (as of 8), in a pseudecode form

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()
@jokester
jokester / curl-server-cert.sh
Created December 27, 2018 03:32
print server certificate (for expiration check and stuff)
#!/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 November 7, 2018 07:03
mitmproxy: delay transfer of css response body
# 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
@jokester
jokester / curl-speed-test.sh
Created August 6, 2018 09:15
Test speed with curl
#!/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 07:33
add RefreshControl to FlatList / SectionList in a simpler way
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 06:30
capture screenshot with adb && pull from pc
#!/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"
@jokester
jokester / normalize-screenshot.sh
Created May 1, 2018 02:52
normalize size of smartphone screenshots
#!/usr/bin/env bash
set -ue
set -o pipefail
if [[ $# -ne 3 ]]; then
cat 1>&2 <<END
USAGE: $0 SRC_FILE PHYSICAL_SIZE NEW_FILE
size of DST_FILE (in pixels) will be proportional to PHYSICAL_SIZE (160 DPI)
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

01.道可道,非常道。名可名,非常名。无名天地之始。有名万物之母。故常无欲以观其妙。常有欲以观其徼。此两者同出而异名,同谓之玄。玄之又玄,众妙之门。

02.天下皆知美之为美,斯恶矣;皆知善之为善,斯不善已。故有无相生,难易相成,长短相形,高下相倾,音声相和,前後相随。是以圣人处无为之事,行不言之教。万物作焉而不辞。生而不有,为而不恃,功成而弗居。夫唯弗居,是以不去。

03.不尚贤, 使民不争。不贵难得之货,使民不为盗。不见可欲,使民心不乱。是以圣人之治,虚其心,实其腹,弱其志,强其骨;常使民无知、无欲,使夫智者不敢为也。为无为,则无不治。

04.道冲而用之,或不盈。渊兮似万物之宗。解其纷,和其光,同其尘,湛兮似或存。吾不知谁之子,象帝之先。

05.天地不仁,以万物为刍狗。圣人不仁,以百姓为刍狗。天地之间,其犹橐迭乎?虚而不屈,动而愈出。多言数穷,不如守中。

0 == 588 * 0 + 0
1 == 586 * 0 + 1
2 == 584 * 0 + 2
3 == 582 * 0 + 3
4 == 580 * 0 + 4
5 == 578 * 0 + 5
6 == 576 * 0 + 6
7 == 574 * 0 + 7
8 == 572 * 0 + 8
9 == 570 * 0 + 9