Skip to content

Instantly share code, notes, and snippets.

View BrambleXu's full-sized avatar

BrambleXu BrambleXu

View GitHub Profile
@BrambleXu
BrambleXu / commit-msg-checker.sh
Last active February 13, 2023 08:18 — forked from Umut-Deniz1/commit-msg-checker.sh
Add your own custom commit message check into git hooks. The checker control commit messages whether correct according to conventional commit .
#!/usr/bin/env bash
if [ ! -x .git/hooks/commit-msg ] || [ ! -f .git/hooks/commit-msg ] || ! cmp ./hooks/commit-msg.sh .git/hooks/commit-msg
then
echo -e "\033[33m Setting Up Git commit Hook..."
mkdir -p .git/hooks/
cp ./hooks/commit-msg.sh .git/hooks/commit-msg
chmod +x .git/hooks/commit-msg
echo -e "\033[32m Done"
echo -e "\033[33m You can make commit now."
@BrambleXu
BrambleXu / download_zip_file_&unzip.py
Created October 28, 2022 05:34
download zip file and up zip
import os
import tarfile
import urllib.request
from datetime import datetime
import zipfile
data_dir = "./data/"
if not os.path.exists(data_dir):
os.mkdir(data_dir)
@BrambleXu
BrambleXu / History|-1092e9ab|entries.json
Last active October 6, 2022 06:19
Convert jsonl bytes to string
{"version":1,"resource":"file:///Users/smap/Project/seqal/seqal/stoppers/__init__.py","entries":[{"id":"F4pE.py","timestamp":1658194872996}]}
import unicodedata
from typing import List
from pathlib import Path
from collections import defaultdict
from ahocorasick import Automaton
def read_dictionary(dict_path: str) -> dict:
with open(dict_path, 'r', encoding='utf-8') as f:
from typing import List, Dict, Sequence
class Matrics:
def __init__(self, sents_true_labels: Sequence[Sequence[Dict]], sents_pred_labels:Sequence[Sequence[Dict]]):
self.sents_true_labels = sents_true_labels
self.sents_pred_labels = sents_pred_labels
self.types = set(entity['type'] for sent in sents_true_labels for entity in sent)
self.confusion_matrices = {type: {'TP': 0, 'TN': 0, 'FP': 0, 'FN': 0} for type in self.types}
self.scores = {type: {'p': 0, 'r': 0, 'f1': 0} for type in self.types}
"""
pip install torch==1.4.0 torchvision==0.5.0 tensorboard==2.1.0
command:
python tensorboard_epoch_demo.py
tensorboard --logdir=runs
"""
import torch
import torch.nn as nn
@BrambleXu
BrambleXu / tensorboard_demo.py
Created January 18, 2020 02:00
TensorBoard with PyTorch
import torch
import torch.nn as nn
import torch.optim as optim
import torch.nn.functional as F
import torchvision
import torchvision.transforms as transforms
from torch.utils.tensorboard import SummaryWriter
print(torch.__version__)
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
%matplotlib inline
st = {2: 1478515,
3: 449113,
4: 646495,
5: 166796,
@BrambleXu
BrambleXu / github_api_realtime.py
Created November 29, 2019 01:39
Get activity stream by GitHub API
import requests
headers ={
'Authorization': 'token <TOKEN>', # replace <TOKEN> with your token
}
response = requests.get('https://api.github.com/users/<username>/received_events', headers=headers) # replace <username> with your user name
data = response.json()
event_actions = {'WatchEvent': 'starred', 'PushEvent': 'pushed to'}
@BrambleXu
BrambleXu / material_downloader.py
Last active November 18, 2019 23:51
A simple crawler example to build a course material downloader
import os
import requests
from lxml import etree
import wget
# prepare
download_directory = 'slides/'
url = 'http://inst.eecs.berkeley.edu/~cs61a/fa18/'
# make request