Skip to content

Instantly share code, notes, and snippets.

@cccntu
cccntu / utils.py
Created July 22, 2020 11:44
python utils
import json
def read_json(path, encoding = 'utf-8'):
with open(path, encoding = encoding) as f:
return json.load(f)
def write_json(data, path, encoding = 'utf-8'):
with open(path, 'w', encoding = encoding) as f:
return json.dump(data, f)
@cccntu
cccntu / gist:e217dfa9a39ff837b948b03bc3afc1da
Created May 30, 2020 12:27
access images on server over ssh, without downloading, using one-line python http server
local_account@local_hostname$ ssh -L 12345:0.0.0.0:12345 remote_account@remote_hostname
remote_account@remote_hostname$ python -m http.server 12345
# open http://localhost:12345/ on local computer browser
@cccntu
cccntu / gist:b113a2a562c15e6487c3daf898f5193a
Last active May 30, 2020 03:15
Crack password from shadow file: Install john the ripper on ubuntu with gpu support
Usage (Official Repo):
https://github.com/magnumripper/JohnTheRipper
Ubuntu Install Guide:
https://github.com/magnumripper/JohnTheRipper/blob/bleeding-jumbo/doc/INSTALL-UBUNTU
Other install guides can be found in:
https://github.com/magnumripper/JohnTheRipper/blob/bleeding-jumbo/doc/
https://github.com/magnumripper/JohnTheRipper/blob/bleeding-jumbo/doc/INSTALL
https://github.com/magnumripper/JohnTheRipper/blob/bleeding-jumbo/doc/INSTALL-FEDORA
@cccntu
cccntu / r.md
Last active May 30, 2020 11:12
Install r package in shell for r-beginner
from argparse import ArgumentParser
def main(args):
if __name__ == '__main__':
parser = ArgumentParser()
parser.add_argument('--int', type=int, default=0, help='')
parser.add_argument('--str', type=str, default='', help='')
parser.add_argument('--action', action='store_true', help='')
args = parser.parse_args()
# args = parser.parse_args('') if in jupyter notebook
@cccntu
cccntu / torch_set_seed.py
Last active May 21, 2020 05:54
make pytroch code reproducible
import random
import numpy as np
import torch
def set_seed(seed):
random.seed(seed)
np.random.seed(seed)
torch.manual_seed(seed)
torch.cuda.manual_seed_all(seed)
torch.backends.cudnn.deterministic = True
torch.backends.cudnn.benchmark = False
"""
讓encoder能disentangleword跟style才會學得好 像fontgan那樣
相同的word/style的embedding要接近,用F.pairwise_distance
然後要能decode出來,用l1_loss,
"""
class Encoder(nn.Module):
def __init__():
self.encoder = Encoder()
self.style = nn.Linear()