Skip to content

Instantly share code, notes, and snippets.

View breezewish's full-sized avatar

Wenxuan breezewish

  • Shanghai, China ⇋ Guangzhou, China
  • 19:04 (UTC +08:00)
  • LinkedIn in/breezewish
View GitHub Profile
@breezewish
breezewish / grafana-export.js
Created August 18, 2020 14:53
Export current Grafana dashboard (for Grafana v6.x.x)
(function () {
function escapeHtml(unsafe) {
return unsafe
.replace(/&/g, "&")
.replace(/</g, "&lt;")
.replace(/>/g, "&gt;")
.replace(/"/g, "&quot;")
.replace(/'/g, "&#039;");
}
#!/usr/bin/python
from __future__ import print_function
import argparse
import json
import os
import sys
def collect_mtime_list(path):
@breezewish
breezewish / simple-maco.rs
Created February 3, 2019 08:29
A simple procedural macro that generates a static metric for rust-prometheus.
extern crate proc_macro;
use quote::quote;
use proc_macro::TokenStream;
use syn::*;
use syn::parse::{Parse, ParseStream};
#[derive(Debug)]
struct MetricDefinition {
vis: Visibility,
@breezewish
breezewish / prometheus-sample.rs
Created February 2, 2019 13:09
A getting started example for rust-prometheus + hyper
#[macro_use]
extern crate lazy_static;
use hyper::rt::Future;
use hyper::service::service_fn_ok;
use hyper::{Body, Request, Response, Server};
use prometheus::*;
use rand::prelude::*;
lazy_static! {
@breezewish
breezewish / ast_vs_rpn.rs
Last active March 6, 2020 10:30
AST vs RPN evaluation performance. JavaScript version: https://gist.github.com/koorchik/9717b893ae2134e21dbe
//! AST vs RPN evaluation performance in Rust language.
#![feature(test)]
extern crate test;
#[derive(Clone, Copy, Debug)]
pub enum Function {
Plus,
Minus,
@breezewish
breezewish / protobufjs-stream-decoder.js
Last active January 9, 2024 04:27
Protobuf.js 6+ Stream Decoder
import through2 from 'through2';
import { BufferReader } from 'protobufjs';
function decodeProtobuf(decodeFunc, msgMaxSize = 20 * 1000 * 1000) {
const buffer = Buffer.alloc(msgMaxSize);
const reader = new BufferReader(buffer);
let bufferLen = 0; // The length of valid data in buffer, may contain multiple messages
reader.pos = 0;
@breezewish
breezewish / webgl_renderer.js
Created April 30, 2018 15:20
GPU Accelerated Image Rendering (RGBA in Uint8Array) using WebGL
(function () {
const VERTEX_SHADER = `
attribute vec4 a_position;
attribute vec2 a_texcoord;
varying vec2 v_texcoord;
void main() {
gl_Position = a_position;
@breezewish
breezewish / typora-theme.css
Created January 3, 2018 05:34
my personal Typora theme
@include-when-export url(http://fonts.googleapis.com/css?family=Open+Sans:400italic,700italic,700,400&subset=latin,latin-ext);
@font-face {
font-family: 'Open Sans';
font-style: normal;
font-weight: normal;
src: local('Open Sans Regular'),url('./github/400.woff') format('woff')
}
@font-face {
@breezewish
breezewish / matplotlib-ms-word.md
Created June 5, 2017 07:12
Insert matplotlib charts as vector image to MS Word

Purpose

MS Word 2016 do support svg. But they are rasterized when exporting to PDF currently. Here is a workaround.

Steps

  1. Export as svg

  2. Use inkscape to convert dash into paths

@breezewish
breezewish / biaori-to-anki.js
Last active March 21, 2024 01:09
将《新标准日语》的音频和单词导入到 Anki https://zhuanlan.zhihu.com/p/58139619
const assert = require("assert").strict;
const child_process = require("child_process");
const path = require("path");
const crypto = require("crypto");
const glob = require("glob");
const fs = require("fs-extra");
const _ = require("lodash");
const sort = require("alphanum-sort");
const Kuroshiro = require("kuroshiro");
const KuromojiAnalyzer = require("kuroshiro-analyzer-kuromoji");