This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import contextlib | |
import time | |
@contextlib.contextmanager | |
def stopwatch(message): | |
"""Context manager to print how long a block of code took.""" | |
t0 = time.time() | |
try: | |
yield | |
finally: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
client = paramiko.SSHClient() | |
client._policy = paramiko.WarningPolicy() | |
client.set_missing_host_key_policy(paramiko.AutoAddPolicy()) | |
ssh_config = paramiko.SSHConfig() | |
user_config_file = os.path.expanduser("~/.ssh/config") | |
if os.path.exists(user_config_file): | |
with open(user_config_file) as f: | |
ssh_config.parse(f) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import socket | |
def pick_unused(): | |
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
s.bind(('localhost', 0)) | |
addr, port = s.getsockname() | |
s.close() | |
return port |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <termios.h> | |
#include <unistd.h> | |
#include <fcntl.h> | |
int kbhit(void) { | |
struct termios oldt, newt; | |
int ch; | |
int oldf; | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
echo "" | |
read -e -p "Target folder name: " folder | |
echo "Duplicate folder structure of $folder.." | |
if [ -d "Compressed-${folder}" ]; then | |
echo "" | |
read -r -p "\"Compressed-${folder}\" exist, overwrite? [y/n] " response | |
if [[ $response =~ ^([yY][eE][sS]|[yY])$ ]] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
A fork of this gist https://gist.github.com/BigglesZX/4016539 . | |
Ported to Python3 and verify it with Pillow. | |
''' | |
import argparse | |
import os | |
from PIL import Image | |
def find_dir(path): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import os, argparse, logging | |
# using doc2vec model | |
from gensim.models import Doc2Vec | |
# generate compressed pickle file | |
import pickle, numpy, gzip | |
logging.basicConfig(format='%(asctime)s [%(levelname)s] %(message)s') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import os, sys, argparse, logging | |
baseline = '/tmp2/b03902036/train-punc.pro' | |
result = '/tmp2/b03902036/result.cmb' | |
ground_truth = dict() | |
with open(baseline, 'r') as in_file : | |
for line in in_file : |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from gensim.models.doc2vec import Doc2Vec | |
from gensim.test.test_doc2vec import ConcatenatedDoc2Vec | |
from sklearn.linear_model import LogisticRegression, SGDClassifier, LogisticRegressionCV | |
from sklearn import svm | |
from sklearn.externals import joblib | |
import jieba | |
import numpy as np | |
import logging | |
import os | |
import sys |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import requests, json, sys, random | |
from html.parser import HTMLParser | |
from time import sleep | |
from tqdm import tqdm | |
import cProfile | |
url = 'http://words.sinica.edu.tw/ftms-bin/scripts/words_scripts/zizi1.pl' |