Skip to content

Instantly share code, notes, and snippets.

Avatar

Leo leetschau

View GitHub Profile
@leetschau
leetschau / JsonParser.fsx
Created July 14, 2021 09:33
Understanding Parser Combinators Series
View JsonParser.fsx
/// This is the implementation of the first 2 parts of the wonderful 4-parts
/// posts "Understanding Parser Combinators" of
/// [F# for fun and profit](https://fsharpforfunandprofit.com/):
module ParserLib1 =
open System
/// Type that represents Success/Failure in parsing
type ParseResult<'a> =
@leetschau
leetschau / evint.sh
Last active February 5, 2020 07:23
fetch lines in a file with even intervals and window size
View evint.sh
#!/bin/sh
# Function:
# print $output_num sections by order,
# each have $sec_num adjacent records
# from file $inp
inp=$1
output_num=$2
sec_num=$3
@leetschau
leetschau / achao.zsh-theme
Created December 11, 2019 07:30
my double line oh-my-zsh theme
View achao.zsh-theme
rc=%{$reset_color%}
cy=$fg_bold[cyan]
bl=$fg_bold[blue]
re=$fg_bold[red]
wh=%{$fg_bold[white]%}
ye=$fg_bold[yellow]
gr=$fg_bold[green]
ma=$fg_bold[magenta]
ZSH_THEME_GIT_PROMPT_PREFIX="git("
@leetschau
leetschau / PythonStyleGuide.md
Last active May 31, 2019 02:00
Python Style Guide for BioT
View PythonStyleGuide.md

Python Style Guide

综述

Python 语言最明显的特征之一是用缩进量表示从属关系,没有采用 Java, C 用括号定义作用域的自由书写风格。 所以 Python 对代码格式的要求十分严格,社区发展出了完整的编码规范和丰富的检查和修复工具,并能够整合到几乎所有主流编辑器中。

编码规范在提升代码质量和可读性、降低维护成本等方面发挥了核心作用,但如果没有相应的工具链帮助其落地,很难真正产生效果,本文第3、4节专门论述如何搭建可用的工具链。

Python 社区不鼓励对编码规范做人工审查,因为人工审查存在如下问题:

@leetschau
leetschau / dataExtractor.sh
Created October 31, 2018 13:55
阳城子光伏数据提取脚本
View dataExtractor.sh
#!/bin/bash
# 使用方法:
# * 提取文件 `ycz6502.csv` 中所有包含的日期,保存到各自的csv文件中:`./filecutter.sh ycz6502.csv`
# * 提取文件 `ycz6502.csv` 中指定日期(2017年6月4日)的数据到csv文件中:./filecutter.sh ycz6502.csv 20170604
sourcefile=$(basename -s .csv $1)
if [[ $# -gt 1 ]]; then
csvgrep -c time -m $2 $1 > $sourcefile-$2.csv
echo "$sourcefile-$2.csv created"
@leetschau
leetschau / quadratic-form.Rmd
Created October 16, 2018 08:21
二次型的Python实现,用于测试 RStudio 中是否能够实现跨 chunk 的 Python 运行
View quadratic-form.Rmd
---
title: "二次型系统的参数估计和异常检测"
output: html_notebook
---
二次型系统([Quadratic form](https://en.wikipedia.org/wiki/Quadratic_form))是只包含二次项,不包含常数和一次项的单变量或者多变量系统,例如下面分别是包含1, 2 和 3个特征变量的二次型系统:
$$
y = a x^2 \\
y = a x^2 + b xy + c y^2 \\
y = a x^2 + b y^2 + c z^2 + d xy + e xz + f yz
@leetschau
leetschau / wavelet-demo.py
Created September 30, 2018 02:12
基于小波分析实现图片降噪的实例
View wavelet-demo.py
import numpy as np
import matplotlib.pyplot as plt
import pywt
original = pywt.data.camera()
noiseSigma = 16.0
image = original + np.random.normal(0, noiseSigma, size=original.shape)
@leetschau
leetschau / r2cor.md
Last active April 3, 2018 09:22
equation demo
View r2cor.md

Let $$ \begin{align} ss_{xy} = \sum(x_i - \bar x) (y_i - \bar y) \tag 1 \end{align} $$

@leetschau
leetschau / pivot_table_demo.py
Last active December 28, 2017 04:08
A Pandas Pivot Table Demo
View pivot_table_demo.py
import pandas as pd
import numpy as np
# based on [Pandas Pivot Table Explained](http://pbpython.com/pandas-pivot-table-explained.html)
# basic pivot table function
df = pd.read_excel('./sales-funnel.xlsx')
df['Status'] = df['Status'].astype('category')
df['Status'].cat.set_categories(["won", "pending", "presented", "declined"], inplace=True)
View getAllModel.groovy
def meta = '''
{
"img": "../../../../static/img/treeImg/project.png",
"name": "财务预算",
"id": "1510126562947",
"open": true,
"level": 0,
"select": false,
"dictoryList": [
{