Skip to content

Instantly share code, notes, and snippets.

View Dixhom's full-sized avatar

dixhom Dixhom

View GitHub Profile
@Dixhom
Dixhom / custom_tqdm.py
Last active November 12, 2023 05:42
custom tqdm
"""
advantages over normal tqdm:
1. progress can be checked more in detail.
a progress bar comes with a number at the end "########6".
This means the last portion is done 60%.
2. The total number of iteration can be changed.
`obj.total_count = new_count`
"""
@Dixhom
Dixhom / day_of_the_week.c
Created July 7, 2023 13:51
Yet another code to get the day of the week from (year, month, day)
int base_year = 1970;
// cumulative days of the year for each month
int daysCumsum[] = {0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365};
char* dayOfTheWeek[] = {"Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"};
int getLeapYear(int year) {
// get num leap years from the year 1
int div4 = year / 4;
int div100 = year / 100;
@Dixhom
Dixhom / day_of_the_week.py
Created July 7, 2023 13:48
Yet another code to get the day of the week from (year, month, day)
def getLeapYear(year):
# get num leap years from the year 1
div4 = year // 4
div100 = year // 100
div400 = year // 400
# number of leap years until `year`
return div4 - div100 + div400
def isLeapYear(year):
# whether `year` is a leap year
@Dixhom
Dixhom / scrape.py
Created June 10, 2023 11:30
scraping-snippet
import requests
from bs4 import BeautifulSoup
url = "https://mansion-market.com/mansions/categories/brands"
r = requests.get(url)
soup = BeautifulSoup(r.content, "html.parser")
# be careful, select() returns a list.
[a.text for a in soup.select('div.article_list')[0].select('li')]
@Dixhom
Dixhom / req_create.py
Last active May 9, 2023 05:10
This code reads import statements from python scripts and creates a requirements_txt.
# About:
# - This code reads import statements from python scripts and creates a requirements_txt.
# Caveats:
# - Sometimes library names in pip and python scripts are different. e.g.) pip install scikit-learn vs import sklearn. The users need to fix the name by themselves.
# Todo:
# - Prepare a conversion table between the library names in pip and python scripts and create the requirements.txt properly.
import pkg_resources
@Dixhom
Dixhom / n_digit_power.py
Created January 15, 2023 06:46
What n-digit number doesn't change the last n-digit of its power?
n = 8
div = 10**n
for i in range(10**(n-1), 10**n):
if (i * i) % div == i:
print(i)
# 2: 25, 76
# 3: 376, 625
# 4: 9376
# 5: 90625
@Dixhom
Dixhom / rational.py
Created November 1, 2022 11:49
Rational numer class
class Rational:
"""
a class to handle rational numbers
"""
def __init__(self, num, denom=1):
self.num = num # numerator
self.denom = denom # denominator
def __gcd(self,u,v):
"""
@Dixhom
Dixhom / gist:d98c4306fcdc783c4e58a77353222d52
Last active October 25, 2022 22:42
auto-size-adjusting-qr-code-generator
# pip install PyQRCode
# pip install pypng
import pyqrcode
import re
def create_qr_code(value=None,
error='L',
version=1,
mode='binary',
@Dixhom
Dixhom / readme.md
Created October 10, 2022 02:29
tree-model-multicollinearity

What is this?

This is a verification to confirm whether a tree based machine learning model causes multicollinearity. This is purely out of my curiosity. I just wondered if multicollinearity takes place in a tree based model and aggravates its performance. If it does, it means one needs to remove correlated features before building models.

Method

I artificially generated three datasets, obtained scores with lightgbm and k-fold cross validation and compared the finals scores.

  1. dataset 1: 10 informative features (useful features for prediction)
  2. dataset 2: 10 informative features + 10 features with random values
@Dixhom
Dixhom / possible-numbers-of-cases-with-a-4x4-board-with-numbers-1-to-4.py
Last active September 23, 2022 07:18
Possible numbers of cases with a 4x4 board with numbers 1 to 4
from tqdm import tqdm
"""
This is a script to solve a math problem.
The number from 1 to 4 will be placed in each cell of a 4 x 4 board.
Each number must appear only once in each row and column of the board.
How many possible numbers of cases are there?
This script is extended to solve the problem with 2^power instead of 4.