Skip to content

Instantly share code, notes, and snippets.

@timcsy
timcsy / imgur.py
Last active May 7, 2024 09:09
備份 HackMD 上面之前上傳到 imgur 的圖片。請到 HackMD 的設定頁面把所有的筆記下載下來,放在 Notes 資料夾裡面,然後把這個 imgur.py 檔放在外面,執行 python imgur.py 之後就可以備份囉!備份後的圖將存到 imgur 資料夾
import os
from glob import glob
import re
import urllib.request
paths = glob('Notes/*.md')
results = []
for path in paths:
with open(path, 'r', encoding='UTF-8') as fin:
data = fin.read()
@timcsy
timcsy / newton.cpp
Last active March 20, 2021 13:31
牛頓法範例
// 比較可以重複利用牛頓法的寫法(使用 function pointer)
#include <iostream>
using namespace std;
typedef double (*Equation)(double x); // 把 function pointer 命名為 Equation
double diff(Equation f, double x, double h=1e-6) {
return (f(x + h) - f(x)) / h;
}
@timcsy
timcsy / list.h
Created January 16, 2018 02:41 — forked from ctlaltlaltc/list.h
Simple doubly linked list implementation, modify from linux kernel list.h, so we can use it in application.
#ifndef _LIST_H
#define _LIST_H
#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
#define container_of(ptr, type, member) ({ \
const typeof( ((type *)0)->member ) *__mptr = (ptr); \
(type *)( (char *)__mptr - offsetof(type,member) );})
struct list_head {
struct list_head *next, *prev;