Skip to content

Instantly share code, notes, and snippets.

@cjwcommuny
cjwcommuny / Main.java
Created September 27, 2023 10:59
Java Jackson Polymorphic Deserialization
package org.example;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonSubTypes;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import com.fasterxml.jackson.annotation.JsonTypeName;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.Builder;
import lombok.SneakyThrows;
import lombok.Value;
@cjwcommuny
cjwcommuny / permission.rs
Last active March 12, 2023 13:40
Permission Pattern for Rust
/// ref: [zhihu](https://zhuanlan.zhihu.com/p/378252833)
use crate::foo::{IncreaseOnly, new_increase_only};
fn main() {
let mut x1 = new_increase_only!(0);
let mut x2 = new_increase_only!(2);
let y = 1;
// only can be used in `x1`
let le = x1.check_less_or_equal(y).unwrap();
{-# LANGUAGE GADTs #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE MultiParamTypeClasses #-}
module Main where
class Monad m => Handler (g :: * -> *) (m :: * -> *) where
handle :: g a -> (a -> m b) -> m b
data Freer :: (* -> *) -> * -> * where
@cjwcommuny
cjwcommuny / main.ts
Created March 16, 2022 04:11
language server extension typescript template.ts
let langserver: ExampleLanguageServer | null = null;
export const activate = function() {
langserver = new ExampleLanguageServer();
}
export const deactivate = function() {
if (langserver) {
langserver.stop();
langserver = null;
@cjwcommuny
cjwcommuny / toggle.js
Created November 6, 2021 07:43
macOS Monterey Toggle Cursor Size
// see https://apple.stackexchange.com/a/430338/433504
function fn() {
const cursorSizeSmall = 1
const cursorSizeLarge = 4
const isRunningSystemPreferences = Application('System Preferences').running()
Application('System Preferences').panes.byId('com.apple.preference.universalaccess').anchors.byName('Seeing_Cursor').reveal()
const process = Application('System Events').processes.byName('System Preferences')
while (process.windows.length == 0) {}
@cjwcommuny
cjwcommuny / MacEditorTextView.swift
Created October 31, 2021 10:46
An NSTextView wrapped by SwiftUI with TextKit 2
/**
* MacEditorTextView
* Copyright (c) Thiago Holanda 2020-2021
* https://twitter.com/tholanda
*
* MIT license
* Modified by https://github.com/cjwcommuny for TextKit 2
*/
import Combine
@cjwcommuny
cjwcommuny / extract_rcnn_box_features_detectron2.py
Last active November 20, 2021 01:03
Detectron2 Extract Box Features
import cv2
import torch
from detectron2.config import get_cfg
from detectron2.engine import DefaultPredictor
from detectron2.model_zoo import model_zoo
from detectron2.utils.visualizer import Visualizer
def extract_box_features(model, image_cv, cfg):
device = cfg.MODEL.DEVICE
def show_opencv_image(image):
from matplotlib import pyplot as plt
image = image[:,:,::-1]
plt.imshow(image)
plt.show()
@cjwcommuny
cjwcommuny / QuantumultX_js.conf
Created October 17, 2021 03:03
QuantumultX Config
^https?://(www\.)?g\.cn url 302 https://www.google.com
^https?://(www\.)?google\.cn url 302 https://www.google.com
^https?://(www\.)?google\.cn/search url 302 https://www.google.com/search
conda install pytorch torchvision torchaudio cudatoolkit=10.2 -c pytorch -y # Linux
conda install -c conda-forge tensorflow -y
conda install -c conda-forge mypy -y
conda install -c anaconda seaborn -y
conda install -c anaconda pandas -y
conda install -c conda-forge matplotlib -y
conda install -c anaconda scikit-learn -y
pip install opencv-contrib-python-headless # support opencl instead of using conda, headless for server
conda install -c anaconda jupyter -y
conda install -c conda-forge pytorch-lightning -y