Skip to content

Instantly share code, notes, and snippets.

@AFutureD
AFutureD / Share SSR.js
Last active May 14, 2021 09:02
把shadowrocket的二维码转为 ssr 链接。
$app.strings = {
"en": {
"title1": "Clipboard Saved",
"title2": "Open URL",
"title3": "Cancel",
"title4": "Clipboard Saved",
"title5": "OK",
"title6": "QR Code Error",
"title7": "OK",
"title8": "QR Decoder",
@AFutureD
AFutureD / convert.py
Created August 20, 2019 08:55
Tensor to cv2
img = transforms.functional.to_pil_image(img)
img = cv2.cvtColor(np.asarray(img),cv2.COLOR_RGB2BGR)
@AFutureD
AFutureD / chang app to zh-CN.sh
Created August 21, 2019 02:12
chang app to zh-CN #macOS
setAppL(){
APPPATH=$1
APPID=$(mdls -name kMDItemCFBundleIdentifier $APPPATH | cut -d'"' -f2)
defaults write $APPID AppleLanguages '(zh-CN)'
}
@AFutureD
AFutureD / Template.cpp
Created September 1, 2019 14:05
Cpp Template
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>
#include <cmath>
#include <cstring>
#include <map>
#include <set>
#include <stack>
@AFutureD
AFutureD / sort within DFgroupby
Last active January 16, 2020 03:39
pandas sort within DFgroupby
JPEG_INFO.groupby(['plant','classes']).count()
path. id
plant classes
小麦 小麦_叶锈病 94 94
小麦_壳针孢叶斑病 47. 47
小麦_散黑穗病 492. 492
小麦_条锈病 1837. 1837
小麦_白粉病 1071. 1071
小麦_纹枯病 398. 398
@AFutureD
AFutureD / pytorch_model_shape_test.py
Last active January 16, 2020 03:35
Pytorch test model's shape
img = np.random.randint(0,256,(4,3,512,512)) # (4,3,512,512) => batch size, channel, height, width
img = torch.from_numpy(img).float().div(255) # convert numpy to tensor and scale to 0-1.
cbam_tmp = resnet50_cbam() # create a model.
cbam_tmp(img)
@AFutureD
AFutureD / show mask on the image.py
Created January 16, 2020 03:37
Apple mask on a image.
def random_colors(self, N, bright=True):
"""
Generate random colors.
To get visually distinct colors, generate them in HSV space then
convert to RGB.
"""
brightness = 1.0 if bright else 0.7
hsv = [(i / N, 1, brightness) for i in range(N)]
colors = list(map(lambda c: colorsys.hsv_to_rgb(*c), hsv))
random.shuffle(colors)
@AFutureD
AFutureD / Inherit_Path.python
Created April 28, 2020 08:19
#Python #Inherit pathlib.Path
from pathlib import Path
class DataSetPath(type(Path())):
def __new__(cls, *args, **kwargs):
path = cls
return super().__new__(cls, *args, **kwargs)
def __mod__(self, other):
return self.parent / (str(self.name) % other)
@AFutureD
AFutureD / Hypothesis.user.js
Last active January 7, 2024 23:00
A Tempermonkey script for Hypothes.is
// ==UserScript==
// @name Hypothesis
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author AFuture
// @match *://*/*
// @grant none
// ==/UserScript==
fl () {
API=""
ret_json=$(curl -s -H "Content-Type: application/json" -X POST -d "{\"content\":\"$*\"}" $API)
echo $ret_json | sed "s/.*\"message\":\([^,}]*\).*/\1/"
}