Skip to content

Instantly share code, notes, and snippets.

Avatar

Wenxuan breeswish

View GitHub Profile
@breeswish
breeswish / grafana-export.js
Created Aug 18, 2020
Export current Grafana dashboard (for Grafana v6.x.x)
View grafana-export.js
(function () {
function escapeHtml(unsafe) {
return unsafe
.replace(/&/g, "&")
.replace(/</g, "&lt;")
.replace(/>/g, "&gt;")
.replace(/"/g, "&quot;")
.replace(/'/g, "&#039;");
}
View cargo-mtime.py
#!/usr/bin/python
from __future__ import print_function
import argparse
import json
import os
import sys
def collect_mtime_list(path):
@breeswish
breeswish / simple-maco.rs
Created Feb 3, 2019
A simple procedural macro that generates a static metric for rust-prometheus.
View simple-maco.rs
extern crate proc_macro;
use quote::quote;
use proc_macro::TokenStream;
use syn::*;
use syn::parse::{Parse, ParseStream};
#[derive(Debug)]
struct MetricDefinition {
vis: Visibility,
@breeswish
breeswish / prometheus-sample.rs
Created Feb 2, 2019
A getting started example for rust-prometheus + hyper
View prometheus-sample.rs
#[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! {
@breeswish
breeswish / ast_vs_rpn.rs
Last active Mar 6, 2020
AST vs RPN evaluation performance. JavaScript version: https://gist.github.com/koorchik/9717b893ae2134e21dbe
View ast_vs_rpn.rs
//! AST vs RPN evaluation performance in Rust language.
#![feature(test)]
extern crate test;
#[derive(Clone, Copy, Debug)]
pub enum Function {
Plus,
Minus,
@breeswish
breeswish / protobufjs-stream-decoder.js
Last active May 15, 2018
Protobuf.js 6+ Stream Decoder
View protobufjs-stream-decoder.js
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;
@breeswish
breeswish / webgl_renderer.js
Created Apr 30, 2018
GPU Accelerated Image Rendering (RGBA in Uint8Array) using WebGL
View webgl_renderer.js
(function () {
const VERTEX_SHADER = `
attribute vec4 a_position;
attribute vec2 a_texcoord;
varying vec2 v_texcoord;
void main() {
gl_Position = a_position;
@breeswish
breeswish / typora-theme.css
Created Jan 3, 2018
my personal Typora theme
View typora-theme.css
@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 {
@breeswish
breeswish / matplotlib-ms-word.md
Created Jun 5, 2017
Insert matplotlib charts as vector image to MS Word
View matplotlib-ms-word.md

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

@breeswish
breeswish / biaori-to-anki.js
Last active Feb 21, 2021
将《新标准日语》的音频和单词导入到 Anki https://zhuanlan.zhihu.com/p/58139619
View biaori-to-anki.js
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");