This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
def normalize_text(t: str): | |
""" | |
:param t: English text | |
:return: Normalized text according to below: | |
# language-dependent part (assuming Western languages): | |
$norm_text = " $norm_text "; | |
$norm_text =~ tr/[A-Z]/[a-z]/ unless $preserve_case; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Usage: | |
# | |
# $socks5ping.py www.baidu.com | |
# Connected to www.baidu.com[:80]: seq=1 time=1.47s | |
# Connected to www.baidu.com[:80]: seq=2 time=1.27s | |
# Connected to www.baidu.com[:80]: seq=3 time=1.18s | |
# Connected to www.baidu.com[:80]: seq=4 time=1.15s | |
# | |
# $socks5ping.py -h | |
# usage: socks5ping.py [-h] [-s SOCKS5HOST] [-o SOCKS5PORT] [-p PORT] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CallbackSequence extends Function { | |
constructor() { | |
super(); | |
this.callbacks = {}; | |
return new Proxy(this, { | |
apply: (target, thisArg, argumentsList) => { | |
this.__call__(); | |
} | |
}); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
rm -rf "${HOME}/Library/Caches/CocoaPods" | |
rm -rf "`pwd`/Pods/" | |
pod update |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"iPhone 6": { | |
"height": 667, | |
"width": 375 | |
}, | |
"iPhone 7": { | |
"height": 667, | |
"width": 375 | |
}, | |
"iPhone 8": { |
OlderNewer