Skip to content

Instantly share code, notes, and snippets.

@liu-sun
liu-sun / stembranch.py
Created November 24, 2023 14:22
object-oriented programming (OOP)
import datetime
from functools import singledispatch
stem = "甲乙丙丁戊己庚辛壬癸"
branch = "子丑寅卯辰巳午未申酉戌亥"
@singledispatch
def stembranch(year):
return stem[(year - 4) % 10] + branch[(year - 4) % 12]
@liu-sun
liu-sun / class.py
Created October 4, 2022 14:45
Date class
from datetime import date
stem = "甲乙丙丁戊己庚辛壬癸"
branch = "子丑寅卯辰巳午未申酉戌亥"
ZODIAC = "鼠牛虎兔龙蛇马羊猴鸡狗猪"
STEMBRANCH = (
'甲子', '乙丑', '丙寅', '丁卯', '戊辰', '己巳', '庚午', '辛未', '壬申', '癸酉', '甲戌', '乙亥', '丙子', '丁丑',
'戊寅', '己卯', '庚辰', '辛巳', '壬午', '癸未', '甲申', '乙酉', '丙戌', '丁亥', '戊子', '己丑', '庚寅', '辛卯',
'壬辰', '癸巳', '甲午', '乙未', '丙申', '丁酉', '戊戌', '己亥', '庚子', '辛丑', '壬寅', '癸卯', '甲辰', '乙巳',
'丙午', '丁未', '戊申', '己酉', '庚戌', '辛亥', '壬子', '癸丑', '甲寅', '乙卯', '丙辰', '丁巳', '戊午', '己未',
from collections import Counter
from pprint import pprint
import matplotlib.pyplot as plt
import pandas as pd
import plotly.express as px
import seaborn as sns
from Bio import Medline
journal = []
@liu-sun
liu-sun / plot.R
Created June 5, 2022 14:00
R ggplot2
ggplot(data=global500)+stat_count(mapping = aes(y=Country))
ggplot(data=global500)+stat_count(mapping = aes(Country))
ggplot(data=global500)+stat_boxplot(mapping = aes(Country, Revenue))
ggplot(data=global500)+stat_boxplot(mapping = aes(y=Country, Revenue))
@liu-sun
liu-sun / seq.py
Created April 6, 2022 03:05
visualization amino acid count by plotly
from collections import Counter
import pandas as pd
import plotly.express as px
from Bio import Entrez, SeqIO
Entrez.api_key = ""
Entrez.email = ""
term = 'TMPRSS6[GENE] AND "refseq select"[filter] AND human[organism]'
handle = Entrez.esearch(db="protein", term=term)
@liu-sun
liu-sun / stembranch.c
Created March 6, 2022 07:49
C实现六十干支
#include <stdio.h>
int main() {
char *stem[] = {"甲", "乙", "丙", "丁", "戊", "己", "庚", "辛", "壬", "癸"};
char *branch[] = {"子", "丑", "寅", "卯", "辰", "巳", "午", "未", "申", "酉", "戌", "亥"};
int i = 0;
while (i < 60) {
printf("%s%s\n", stem[i%10], branch[i%12]);
i++;
}
@liu-sun
liu-sun / stembranch.c
Created March 6, 2022 01:56
干支的C实现
#include <stdio.h>
void stembranch(int year) {
char *stem[] = {"甲", "乙", "丙", "丁", "戊", "己", "庚", "辛", "壬", "癸"};
char *branch[] = {"子", "丑", "寅", "卯", "辰", "巳", "午", "未", "申", "酉", "戌", "亥"};
printf("%s%s\n", stem[(year - 4) % 10], branch[(year - 4) % 12]);
}
int main() {
int year;
@liu-sun
liu-sun / stembranch.R
Created November 2, 2021 06:56
天干地支
stem <- c("甲", "乙", "丙", "丁", "戊", "己", "庚", "辛", "壬", "癸")
branch <- c("子", "丑", "寅", "卯", "辰", "巳", "午", "未", "申", "酉", "戌", "亥")
stembranch <- function(year) {
return(paste0(stem[(year-3)%%10], branch[(year-3)%%12]))
}
@liu-sun
liu-sun / StemBranch.java
Created September 29, 2021 13:19
干支和平闰
public class StemBranch {
public static String stemBranch(int year) {
String[] stem = {"甲", "乙", "丙", "丁", "戊", "己", "庚", "辛", "壬", "癸"};
String[] branch = {"子", "丑", "寅", "卯", "辰", "巳", "午", "未", "申", "酉", "戌", "亥"};
return stem[(year - 4) % 10] + branch[(year - 4) % 12];
}
public static boolean leap(int year) {
if (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0)) {
return true;
import itertools
for i, j, k in itertools.product("ATCG", "ATCG", "ATCG"):
print(i + j + k)