Skip to content

Instantly share code, notes, and snippets.

View BrambleXu's full-sized avatar

BrambleXu BrambleXu

View GitHub Profile
@BrambleXu
BrambleXu / pygame_install.md
Created November 5, 2018 13:46
Installing Pygame, Python 3.6 with Anaconda on OS X

Please make sure you already install the Anaconda.

I will create a virtual environment with anaconda and install the pygame in this virtual environment.

  • First create a virtual environment called pygame and install the Python 3.6 version.
conda create --name pygame python=3.6
  • Change to the pygame virtual environment.
@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}]}
from collections import OrderedDict
import numpy as np
import spacy
from spacy.lang.en.stop_words import STOP_WORDS
nlp = spacy.load('en_core_web_sm')
class TextRank4Keyword():
"""Extract keywords from text"""
@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 / glove2npy.py
Last active June 13, 2021 06:53
load glove and show the progress, finally save to numpy file
import numpy as np
from tqdm import tqdm
def load_glove(file):
"""Loads GloVe vectors in numpy array.
Args:
file (str): a path to a glove file.
Return:
dict: a dict of numpy arrays.
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