Skip to content

Instantly share code, notes, and snippets.

View goddoe's full-sized avatar

Sungju Kim goddoe

View GitHub Profile
@goddoe
goddoe / publish quality graph using matplotlib.py
Created September 10, 2019 06:07
publish quality graph using matplotlib
plt.rc('font', family='serif')
plt.rc('xtick', labelsize='x-large')
plt.rc('ytick', labelsize='x-large')
# plt.rc('text', usetex=True)
plt.rc('axes', labelsize='x-large')
fig = plt.figure(figsize=(6, 6))
ax = fig.add_subplot(1, 1, 1)
@goddoe
goddoe / SelfAttention.py
Created September 15, 2019 10:36
SelfAttention
import torch
import torch.nn as nn
class SelfAttention(nn.Module):
def __init__(self, input_dim, output_dim, dropout=0.1):
super(SelfAttention, self).__init__()
self.q = nn.Linear(input_dim, output_dim)
self.k = nn.Linear(input_dim, output_dim)
@goddoe
goddoe / SelfAttention.py
Last active September 15, 2019 11:03
SelfAttention
import torch
import torch.nn as nn
class SelfAttention(nn.Module):
def __init__(self, input_dim, output_dim, dropout=0.1):
super(SelfAttention, self).__init__()
self.q = nn.Linear(input_dim, output_dim)
self.k = nn.Linear(input_dim, output_dim)
self.v = nn.Linear(input_dim, output_dim)
@goddoe
goddoe / pytorch digit to one hot.py
Last active December 13, 2019 07:38
pytorch digit to one hot
# Reference : https://discuss.pytorch.org/t/convert-int-into-one-hot-format/507/3
# author : albanD
import torch
batch_size = 5
nb_digits = 10
# Dummy input that HAS to be 2D for the scatter (you can use view(-1,1) if needed)
y = torch.LongTensor(batch_size,1).random_() % nb_digits
# One hot encoding buffer that you create out of the loop and just keep reusing
@goddoe
goddoe / plot_surface.py
Created January 23, 2020 07:13
plot_surface
# Reference : https://stackoverflow.com/questions/3461869/plot-a-plane-based-on-a-normal-vector-and-a-point-in-matlab-or-matplotlib/23006541
# author : Simon Streicher, Alexey Grigorev
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
point = np.array([1, 2, 3])
normal = np.array([1, 1, 2])
@goddoe
goddoe / how.md
Created March 3, 2020 11:03
How not to screw my path, when using tmux, conda together

If you're on a Mac and have been wondering why /usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin keeps getting prepended to PATH when you run tmux, it's because of a utility called path_helper that's run from your /etc/profile file.

You can't easily persuade tmux (or rather, bash) not to source /etc/profile (for some reason tmux always runs as a login shell, which means /etc/profile will be read), but you can make sure that the effects of path_helper don't screw with your PATH.

The trick is to make sure that PATH is empty before path_helper runs. In my ~/.bash_profile file or ~/.zshrc I have this:

if [ -f /etc/profile ]; then
    PATH=""
 source /etc/profile
@goddoe
goddoe / resource_check.py
Created March 9, 2020 13:41
resource check
import argparse
from torch.utils.tensorboard import SummaryWriter
import psutil
import time
def bytesto(bytes, to, bsize=1024):
"""convert bytes to megabytes, etc.
sample code:
@goddoe
goddoe / tts.py
Created March 20, 2020 09:54
tts
from gtts import gTTS
from pygame import mixer
import mutagen.mp3
while True:
query = input("query: ")
tts = gTTS(text=query, lang='ko')
tts.save("./out.mp3")
@goddoe
goddoe / browser_visit_fake.py
Created March 23, 2020 15:43
How to use Python requests to fake a browser visit?
import requests
url = 'http://www.ichangtou.com/#company:data_000008.html'
headers = {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36'}
response = requests.get(url, headers=headers)
print(response.content)
@goddoe
goddoe / speedup_pip.md
Created May 5, 2020 05:22
카카오 PyPI 미러 적용