Skip to content

Instantly share code, notes, and snippets.

View goddoe's full-sized avatar

Sungju Kim goddoe

View GitHub Profile
@goddoe
goddoe / How to change default editor of git.md
Last active February 14, 2019 05:52
How to change default editor of git
git config --global core.editor "vim"

if you want to set the editor for Git and also other programs, set the standardized VISUAL and EDITOR environment variables*:

export VISUAL=vim
export EDITOR="$VISUAL"
@goddoe
goddoe / Increase container volume(disk) size
Created February 21, 2019 15:36
Increase container volume(disk) size
With Centos 7 I did the following to increase the default size of the containers
Modify the docker config in /etc/sysconfig/docker-storage to add the line:
DOCKER_STORAGE_OPTIONS= - -storage-opt dm.basesize=20G
service docker stop
rm /var/lib/docker NOTE THIS DELETES ALL IMAGES etc. SO MAKE A BACKUP
service docker start
docker load < [each_save_in_backup.tar]
docker run -i -t [imagename] /bin/bash
@goddoe
goddoe / save_data_parallel_model.py
Created March 19, 2019 15:48
pytorch: save data parallel model
try:
state_dict = model.module.state_dict()
except AttributeError:
state_dict = model.state_dict()
@goddoe
goddoe / weight_init.py
Created March 26, 2019 04:48 — forked from jeasinema/weight_init.py
A simple script for parameter initialization for PyTorch
#!/usr/bin/env python
# -*- coding:UTF-8 -*-
import torch
import torch.nn as nn
import torch.nn.init as init
def weight_init(m):
'''
@goddoe
goddoe / ctags.sh
Created April 2, 2019 09:21
ctags
# https://www.fusionbox.com/blog/detail/navigating-your-django-project-with-vim-and-ctags/590/
ctags -R --fields=+l --languages=python --python-kinds=-iv ./
@goddoe
goddoe / solution.txt
Last active May 21, 2024 16:04
ssh: connect to host bitbucket.org port 22: Connection timed out
I have done below mentioned things and it started working.
vim ~/.ssh/config
Add these lines and save it.
Host github.com
Hostname ssh.github.com
Port 443
Host bitbucket.org
@goddoe
goddoe / timeout.py
Last active July 24, 2019 16:10
Timeout
from functools import wraps
import errno
import os
import signal
class TimeoutError(Exception):
pass
@goddoe
goddoe / repeat vs expand pytorch.py
Created July 30, 2019 09:16
repeat vs expand pytorch
import torch
A = torch.randn([12, 9, 64])
B = torch.randn([12, 9, 64])
Ar = A.repeat(1, 1, 9).view(12, 81, 64)
Br = B.repeat(1, 9, 1)
C = torch.cat((Ar, Br), dim=2)
D = torch.cat([A.unsqueeze(2).expand(-1, -1, 9, -1),
B.unsqueeze(1).expand(-1, 9, -1, -1)], dim=-1).view(12, 81, 128)
print ((C-D).abs().max().item()) # should be 0
@goddoe
goddoe / write_read_tsv.py
Last active August 16, 2019 08:24
tsv write and read using csv package.
import os
from collections import namedtuple
from ast import literal_eval
from os.path import dirname
export_path = "path/to/export"
# Read & Write using native python
# write tsv
os.makedirs(dirname(export_path), exist_ok=True)
@goddoe
goddoe / python in makefile
Created August 21, 2019 01:13
python in makefile
Reference : xorho, https://stackoverflow.com/questions/2043453/executing-multi-line-statements-in-the-one-line-command-line
80
this style can be used in makefiles too (and in fact it is used quite often).
python - <<EOF
import sys
for r in range(3): print 'rob'
EOF