Skip to content

Instantly share code, notes, and snippets.

View cdfmlr's full-sized avatar
💤
Taking a nap (07:00~19:00) 😴. Back to sleep soon (19:00~07:00) 🛏️!

CDFMLR cdfmlr

💤
Taking a nap (07:00~19:00) 😴. Back to sleep soon (19:00~07:00) 🛏️!
View GitHub Profile
@cdfmlr
cdfmlr / binary_search.py
Created December 7, 2018 06:49
binary_search.py
NOT_FOUND = None
def binarySearch(A, n, x):
p = 0
r = n - 1
while p <= r:
q = (p + r) // 2
if A[q] == x:
return q
@cdfmlr
cdfmlr / blogconfc.py
Last active July 30, 2020 14:05
Complete YAML for hexo blogs
#!/usr/local/bin/python3
# -*- coding: utf-8 -*-
'''
HEXO BLOG YAML CONFIG CHECKER/COMPLETER
@File : blogconfc.py
@Author : CDFMLR
@Time : 2020/07/30 21:49
'''
@cdfmlr
cdfmlr / email_sender.py
Last active August 5, 2020 03:40
Send a email with Python
import os
import os.path
import time
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
from email.mime.application import MIMEApplication
import smtplib
def build_email(subject: str, sender: str, receivers: list, content: str, attachments: list, signature=None) -> MIMEMultipart:
'''
@cdfmlr
cdfmlr / README.md
Last active December 19, 2023 15:38
toy-rpc-golang

toy-rpc-golang

简单 RPC 的 Golang 实现。

@cdfmlr
cdfmlr / README.md
Last active September 19, 2020 12:08
[Intro] Use gRPC in Golang

[Intro] Use gRPC in Golang

一个处理用户信息的 RPC 实例。客户端通过给定用户名,从服务端查询用户信息。

项目结构如下:

grpc
├── client
│   └── main.go
@cdfmlr
cdfmlr / ticker_c_is_not_now.go
Created October 2, 2020 12:15
ticker.C 得到的时间和 time.Now() 可能差距较大,要注意。
package main
import (
"fmt"
"time"
)
// ticker.C 的源码实现是:
// make(chan Time, 1)
// tick 发生时的操作是:
package main
import "fmt"
func GetNext(substr string) []int {
next := make([]int, len(substr))
next[0] = -1
i, j := 0, -1
for i < len(substr)-1 {
@cdfmlr
cdfmlr / proxy.sh
Created July 22, 2021 06:11
proxy.sh takes the http proxy on/off in current env.
echo_help() {
echo "Proxy takes the http proxy on/off in current env.
THIS SOFTWARE IS FOR PERSONAL USE ONLY.
Usage:
proxy <command>
The commands are:
@cdfmlr
cdfmlr / linregress.py
Created August 19, 2021 04:13
Linear Regression with one variable via a Batch Gradient Descent
#
# linregress.py
# Linear Regression with one variable via a Batch Gradient Descent
#
# Created by CDFMLR on 2019/8/28.
# Copyright © CDFMLR. All right reserved.
#
import math
import random
#!python3
# 辅助运行 NeteaseCloudMusicApi 服务:
# 服务挂掉时自动重启,输出某种监视日志
import os
import time
import subprocess
import collections
from queue import Queue