Skip to content

Instantly share code, notes, and snippets.

View yfaming's full-sized avatar

yfaming yfaming

View GitHub Profile
@yfaming
yfaming / mdtoc.rs
Created February 23, 2020 09:04
mdtoc: A handy tool which prints table of contents of markdown file with proper indents
use markedit::{Heading, Matcher};
use pulldown_cmark::{Event, Parser, Tag};
use std::fmt::{self, Display};
use std::fs;
use std::io;
use std::mem;
use structopt::StructOpt;
#[derive(StructOpt, Debug)]
#[structopt(name = "mdtoc", about = "print table of contents of markdown file")]
#define _GNU_SOURCE
#define _XOPEN_SOURCE
#define _DEFAULT_SOURCE
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <pwd.h>
@yfaming
yfaming / multimethod.py
Created September 23, 2016 14:00
A more concise version of multimethod than http://www.artima.com/weblogs/viewpost.jsp?thread=101605
from functools import wraps
class Multimethod(object):
def __init__(self):
self.registry = {}
def __call__(self, *types):
def decorator(func):
self.registry[(types, func.__name__)] = func
var assert = require('assert')
function concat(array, e) {
return [].concat(array, [e])
}
function concatArrays(arrayA, arrayB) {
return [].concat(arrayA, arrayB)
}
@yfaming
yfaming / no_side_effect_sort.js
Last active August 29, 2015 14:11
写一个排序函数,不能有“副作用”
//pre: arr 是数组,其元素是相同类型的。
//post: 函数返回排好序的数组
//要求: 不能有“副作用”。
//arr 的元素不得有增删改,局部变量不得被多次赋值,也不能使用任何对象的有副作用的方法,如数组的 push, pop 等。
//不能用循环语句
function sort(arr) {
//do it here
}