Skip to content

Instantly share code, notes, and snippets.

Avatar
💤
连任中

wang chenyu hanayashiki

💤
连任中
View GitHub Profile
View Setup eslint.md
pnpm install -D eslint @typescript-eslint/parser @typescript-eslint/eslint-plugin eslint-plugin-prettier prettier eslint-plugin-import

.eslintrc.cjs

module.exports = {
  ignorePatterns: ['**/vendors/**'],
  plugins: ['import', '@typescript-eslint', 'prettier'],
  parser: '@typescript-eslint/parser',
@hanayashiki
hanayashiki / benchmarks.mjs
Created Nov 16, 2021
module resolution benchmarks
View benchmarks.mjs
import { build } from 'esbuild'
import typescript from '@rollup/plugin-typescript'
export async function esbuildResolve(id, dir) {
let result
await build({
stdin: {
contents: `import ${JSON.stringify(id)}`,
@hanayashiki
hanayashiki / ios-screen-size.json
Last active Nov 15, 2020
A dictionary of different iPhone screen sizes (until iPhone 12)
View ios-screen-size.json
{
"iPhone 6": {
"height": 667,
"width": 375
},
"iPhone 7": {
"height": 667,
"width": 375
},
"iPhone 8": {
@hanayashiki
hanayashiki / podforceupdate.sh
Created Jul 10, 2020 — forked from mbinna/podforceupdate.sh
Clear CocoaPods cache, re-download and re-install all pods
View podforceupdate.sh
#!/usr/bin/env bash
rm -rf "${HOME}/Library/Caches/CocoaPods"
rm -rf "`pwd`/Pods/"
pod update
@hanayashiki
hanayashiki / EventEmitter.swift
Last active Jul 9, 2020 — forked from brennanMKE/EventEmitter.swift
React Native Event Emitter for RCTEventEmitter in Objective-C and Swift
View EventEmitter.swift
class EventEmitter {
/// Shared Instance.
public static var sharedInstance = EventEmitter()
// ReactNativeEventEmitter is instantiated by React Native with the bridge.
private static var eventEmitter: ReactNativeEventEmitter!
private init() {}
@hanayashiki
hanayashiki / sliding_window.py
Created Dec 28, 2019
2d sliding window implementation for numpy
View sliding_window.py
import numpy as np
from numpy.lib.stride_tricks import as_strided
from typing import *
def sliding_window_2d(a: np.array, wnd_size: Tuple[int, int]):
# a: an nd-array of (height, width, ...rest)
# wnd_size: a tuple of (wnd_width, wnd_height)
# returns an nd-array of (height - wnd_height + 1, width - wnd_width + 1, wnd_height, wnd_width, ...rest)
height, width, *rest = a.shape
s0, s1, *rest_strides = a.strides
View callback-sequence.js
class CallbackSequence extends Function {
constructor() {
super();
this.callbacks = {};
return new Proxy(this, {
apply: (target, thisArg, argumentsList) => {
this.__call__();
}
});
}
@hanayashiki
hanayashiki / patch-arrayBuffer.js
Created Dec 16, 2019
Safari 13.0.4: Blob.arrayBuffer is not a function
View patch-arrayBuffer.js
(function () {
File.prototype.arrayBuffer = File.prototype.arrayBuffer || myArrayBuffer;
Blob.prototype.arrayBuffer = Blob.prototype.arrayBuffer || myArrayBuffer;
function myArrayBuffer() {
// this: File or Blob
return new Promise((resolve) => {
let fr = new FileReader();
fr.onload = () => {
resolve(fr.result);
View server_example.py
import socket
def extract_request_line(request):
first_line = request.split("\r\n")[0]
method, resource, ver = first_line.split(" ")
return method, resource, ver
def respond(method, resource):
if method == "GET" and resource == "/A":
return b"<h1>Resource A from my server!</h1>", 200
@hanayashiki
hanayashiki / json_visualizer.py
Created Jul 18, 2019
Truncate long json objects so that it is human readable
View json_visualizer.py
import sys
import json
max_item = 3
def visualize(obj: dict):
if isinstance(obj, list):
if len(obj) > max_item:
return [visualize(o) for o in obj[0:max_item] + ["(%d items in total)" % len(obj)]]
else: