Skip to content

Instantly share code, notes, and snippets.

@hrz6976
hrz6976 / fetch-compatibility-score.py
Last active November 13, 2021 13:58
Fetch compatibility scores for top 20 most dependended-upon npm packages
import requests
import json
import pandas as pd
from tqdm.auto import tqdm
from xml.dom import minidom
def get_version_history(package: str):
res_df = pd.DataFrame()
url = f"https://registry.npmjs.org/{package}"
res = json.loads(requests.get(url).text)
@hrz6976
hrz6976 / run-cmd.py
Last active October 7, 2022 05:49
python subprocess wrapper & color print
# run command and color print
import subprocess
import os
import sys
import logging
from typing import Dict, Optional, TextIO, Tuple
from io import StringIO
def run_command(command: str,
@hrz6976
hrz6976 / plot_mini_hist.py
Last active January 16, 2022 13:43
Plot a minimalist histogram
import matplotlib
import matplotlib.pyplot as plt
import seaborn as sns
def plot_mini_hist(data: pd.Series, log_scale=False, xlim=None):
"""
:param data: a pandas series containing the `original` data (not to be confused with stats)
:param log_scale: plot x-axis in log scale (optional, default=False)
:param xlim: limit the range of x-axis, e.g. [-100, 300] (optional, default=None)
"""
@hrz6976
hrz6976 / enable_photo_viewer.bat
Last active February 1, 2022 06:21
windows bat scripts
@echo off&cd\&color 0a&cls
reg add "HKLM\SOFTWARE\Microsoft\Windows Photo Viewer\Capabilities\FileAssociations" /v ".jpg" /t REG_SZ /d PhotoViewer.FileAssoc.Tiff /f
reg add "HKLM\SOFTWARE\Microsoft\Windows Photo Viewer\Capabilities\FileAssociations" /v ".jpeg" /t REG_SZ /d PhotoViewer.FileAssoc.Tiff /f
reg add "HKLM\SOFTWARE\Microsoft\Windows Photo Viewer\Capabilities\FileAssociations" /v ".bmp" /t REG_SZ /d PhotoViewer.FileAssoc.Tiff /f
reg add "HKLM\SOFTWARE\Microsoft\Windows Photo Viewer\Capabilities\FileAssociations" /v ".png" /t REG_SZ /d PhotoViewer.FileAssoc.Tiff /f
@hrz6976
hrz6976 / check-server-status.sh
Last active March 21, 2023 06:28
Auto connect to PKU Gateway & send IP Address to ServerChan
#!/bin/bash
###############################################################################
# To Run this script hourly, you need to add the following cron job:
# crontab -e
#
# Add the following line:
# 0 * * * * /path/to/check-server-status.sh
#
# Then save and exit.
# Run func(args) concurrently and aggregate the results
# author: @hehao98 <heh@pku.edu.cn>, @12f23eddde <12f23eddde@gmail.com>
from typing import Callable, Iterable, Optional, Any, Tuple, TypeVar, Union
import time
import traceback
from multiprocess import Pool, cpu_count
from tqdm.auto import tqdm
import pandas as pd
#!/bin/sh
# Capture: http://www.cpcelc.pku.edu.cn/phone/socket.php?apistr=XXXXX
OPERID="XXXXXXXXXXXXXXXXXXXXX"
# Reading Log
READING_LOG="/tmp/eletribot.log"
LOW_THRESHOLD=10
# Serverchan sendkey https://sct.ftqq.com/
SCKEY="YYYYYYYYYYYYYYYYYYYYYYY"
@hrz6976
hrz6976 / download_from_anonymous_github.py
Created October 6, 2022 06:27
Download a repository as a zip archive from anonymous.4open.science
import os
import zipfile
import requests
repo_name = input("Enter 4open.science repository name: ")
api_url = f"https://anonymous.4open.science/api/repo/{repo_name}/files/"
r = requests.get(api_url)
r.raise_for_status()
r_j = r.json()
#!/bin/bash
# This script is used to create a new user on the local system.
# You will be prompted to enter the username (login), the person name, and a password.
# The username, password, and host for the account will be displayed.
# Make sure you execute the script with superuser privileges.
# If you do not supply at least one argument, then you will be prompted for the value.
# Run the script like this:
# sudo ./add-local-user.sh USERNAME [AUTHORIZED KEYS]...
@hrz6976
hrz6976 / clickhouse_ghtorrent.sql
Created May 9, 2023 20:25
Import ghtorrent dataset to clickhouse (clickhouse-client --password <PASSWORD> --send-timeout=3600 --receive-timeout=600 < clickhouse_ghtorrent.sql
SET input_format_null_as_default = 1;
SET input_format_allow_errors_num = 100000;
SET input_format_allow_errors_ratio = 0.1;
SET date_time_input_format = 'best_effort';
CREATE DATABASE IF NOT EXISTS `ghtorrent`;
DROP TABLE IF EXISTS `ghtorrent`.`organization_members` ;
CREATE TABLE `ghtorrent`.`organization_members` (