Passing a function as an argument: Lambda Function

Date Tags Python
f = lambda x: x * 2

is exactly the same thing as

def f(x):
    return x * 2

Lambdas are usually used to create small, anonymous functions. Actually, they are just a syntatic sugar to define functions. The lambda expression above is exactly the same as your function, only without a …

more ...

Using groupBy on multiple columns

Date Tags Python

Group By X means put all those with the same value for X in the one group.

Group By X, Y means put all those with the same values for both X and Y in the one group.

To illustrate using an example, let's say we have the following table …

more ...

Python Object and Reference

Date Tags Python

C/C++中函数传递参数方式有:按值传递 和 按址传递。而在一切皆对象的Python中则完全不可延续C/C++的思想,而是要有可变对 …

more ...


Date Tags Cygwin


#download setup-x86_64.exe
$ cd C:cygwin64
$ ./setup-x86_64.exe -q -P wget, tar, qawk, bzip2, subversion, vim, git
# git clone
$ cd apt-cyg
$ mv apt-cyg /usr/local/bin/
$ apt-cyg --help
$ cygcheck --help …
more ...

Case Class vs Class

Date Tags Scala


  • class的定义:
class BankAccount {
  def deposit(amount: Int): Unit = {
    if (amount > 0) balance = balance + amount
  • case class的定义:
case class Note(name: String, duration: String, octave: Int)
  • 创建BankAccountNote的实例:
val aliceAccount = new BankAccount()
val c3 = Note("C", "Quarter …
more ...

Binary Tree


struct TreeNode {
    int val;
    TreeNode* left;
    TreeNode* right;
    TreeNode(int val) : val(val), left(nullptr), right(nullptr) {}



遍 …

more ...

Auto-generated subtitles for any video

Date Tags Tools


Autosub is a utility for automatic speech recognition and subtitle generation. It takes a video or an audio file as input, performs voice activity detection to find speech regions, makes parallel requests to Google Web Speech API to generate transcriptions for those regions, (optionally) translates them to a different …

more ...

Using loguru and notifiers instead of logging

Date Tags Python

from loguru import logger import tempfile import notifiers

Configuring loguru

def email(file_path: str, to: list):
    with open(file_path, 'r') as file:
        msg =
    if not msg: return
    params = {
        "subject": 'Title',
        "from": "",
        "to": to,
        "host": "",
    notifier = notifiers.get_notifier("email")
    notifier …
more ...

Checking DataFrame/Series missing values

Date Tags Python

Checking DataFrame missing values

cols_missing = frame.columns[frame.isna().any()] asset_img missing_value

Checking Series missing values


has_missing method

from loguru import logger
import pandas as pd
from pandas.core.frame import DataFrame
from pandas.core.series import Series
import traceback

def has_missing(self, values):
    """Check whether …
more ...