Skip to content

Instantly share code, notes, and snippets.

@vlasenkov
vlasenkov / pycom.py
Last active December 31, 2023 19:47
win32com multithreading example (python 2)
# win32com multithreading example
import sys
import time
from threading import Thread
 
sys.coinit_flags = 0  # pythoncom.COINIT_MULTITHREADED == 0
from pythoncom import (CoInitializeEx, CoUninitialize,
                       COINIT_MULTITHREADED, PumpWaitingMessages)
from win32com.client import Dispatch, WithEvents
 
@vlasenkov
vlasenkov / .gitignore
Last active October 7, 2017 14:21
GitHub Python .gitignore template specialised for data science and some IDEs
# IDEs
*.sublime-project
*.sublime-workspace
*.vim
*~
*.swp
*.swo
.idea
# Data files
@vlasenkov
vlasenkov / Python.sublime-settings
Created October 7, 2017 14:12
Python Sublime Text settings
{
"translate_tabs_to_spaces": true,
"tab_size": 4,
"rulers": [72, 79],
"indent_to_bracket": true,
}
@vlasenkov
vlasenkov / .vimrc
Created October 7, 2017 14:21
Basic Python .vimrc
set encoding=utf-8
set nocompatible " required
filetype off " required
" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
" alternatively, pass a path where Vundle should install plugins
@vlasenkov
vlasenkov / run.sh
Last active October 7, 2017 14:38
Bash script for launching distributed TensorFlow training in several processes.
# Simple script for experiments with dsitributed TensorFlow.
# Requires jq utility for JSON parsing. Example JSON file can be found on the gist.
# Args:
# name of script to run, example: train.py
# file with cluster configuration, example: hosts.json
#!/bin/bash
script=$1
hosts=$2
@vlasenkov
vlasenkov / hosts.json
Created October 7, 2017 14:37
Example JSON file with cluster configuration for run.sh script
{
"ps":[
{
"host":"localhost",
"port":2222
}
],
"worker":[
{
"host":"localhost",
import os
os.environ["CUDA_VISIBLE_DEVICES"] = "0"
import torch
import torch.nn as nn
import numpy as np
def get_upsampling_weight(in_channels, out_channels, kernel_size):
"""Make a 2D bilinear kernel suitable for upsampling"""
factor = (kernel_size + 1) // 2
import torch
torch.backends.cudnn.deterministic = True
import torch.nn as nn
class UNet3d(nn.Module):
def __init__(self, activation=nn.ReLU, pooling=nn.MaxPool3d):
super().__init__()
self.down0 = nn.Sequential(
@vlasenkov
vlasenkov / .vimrc
Last active September 19, 2020 10:47
c++ vimrc, for macvim
set nocompatible " be iMproved, required
filetype off " required
" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
" alternatively, pass a path where Vundle should install plugins
"call vundle#begin('~/some/path/here')
" let Vundle manage Vundle, required