Skip to content

Instantly share code, notes, and snippets.

View cccntu's full-sized avatar
:octocat:
On vacation

Jonathan Chang cccntu

:octocat:
On vacation
View GitHub Profile
"""
讓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()
@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
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 / r.md
Last active May 30, 2020 11:12
Install r package in shell for r-beginner
@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 / 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 / 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 / install julia.md
Last active November 9, 2020 15:00
Install Julia and use it in jupyter notebook
conda install -c conda-forge julia
conda activate julia
conda install notebook
julia # use julia REPL to install IJulia (necessary)
> using Pkg
> Pkg.add("IJulia")
@cccntu
cccntu / bug_report_model.py
Last active December 7, 2020 02:32
pytorch-lightning ddp BatchEncoding
# Copyright The PyTorch Lightning team.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
@cccntu
cccntu / shelve-test.py
Last active January 27, 2021 06:46
simple benchmark/test for python shelve
import shelve
import time
# initialize
with shelve.open('shelvedb') as db:
for i in range(10000):
db[f'{i}'] = '{i*2}'
# no caching
with shelve.open('shelvedb') as db:
tic = time.time()