Skip to content

Instantly share code, notes, and snippets.

View nik123's full-sized avatar

Nikita Kodenko nik123

View GitHub Profile
@nik123
nik123 / git_revision.py
Last active August 21, 2018 08:31
Get current git revision in Python
import subprocess
def git_revision_hash(short=True) -> str:
"""
Get current git revision
:param short: True if shortened SHA-1 hash is required (first 7 symbols) and
False otherwise
:return: str representing hash of the current git revision
"""
@nik123
nik123 / print_tensors.py
Last active July 12, 2018 04:54
Print list of tensor names saved in checkpoint
from tensorflow.python import pywrap_tensorflow
import os
model_dir = "model/"
checkpoint_path = os.path.join(model_dir, "model.ckpt")
reader = pywrap_tensorflow.NewCheckpointReader(checkpoint_path)
# Returns list of tuples (tensor_name, tensor_shape)
var_to_shape_map = reader.get_variable_to_shape_map()
@nik123
nik123 / tf_cifar10.py
Created April 9, 2018 12:38
TensorFlow CIFAR10 training
import tensorflow as tf
import numpy as np
import keras as K
from keras import utils
from tensorflow.python.keras.datasets import cifar10
from tensorflow.python.layers.convolutional import Conv2D
from tensorflow.python.layers.core import Dense, Flatten
from tensorflow.python.layers.normalization import BatchNormalization
from typing import Tuple
@nik123
nik123 / VirtualenvCheatSheet.md
Last active January 12, 2021 05:59
Virtualenv Cheat Sheet (ru)

Virtualenv + PiP cheatsheet

PiP - система управления пакетами в Python. PiP используется для установки сторонних библиотек (NumPy, SciPy и т.д.).

Virtualenv - инструмент для создания отдельного виртуального окружения. Зачем нужно окружение? По умолчанию PiP устанавливает проекты глобально (на уровне юзера), т.е. после установки пакеты видны всем python-скриптам, запускаемым от вашего имени. Если разные проекты требуют разных версий библиотек, то могут возникнуть проблемы. Virtualenv позволяет создать изолированное окружение с изолированным набором пакетов.

Создание виртуального окружения

В каталоге проекта выполнить команду:

@nik123
nik123 / NKCollectionViewArrayDataSource.h
Last active December 25, 2017 16:45
Array data source for collection views with only one section
#import <UIKit/UIKit.h>
typedef void (^NKCollectionCellConfigurationBlock)(__kindof UICollectionViewCell *cell, id item);
@interface NKCollectionViewArrayDataSource : NSObject <UICollectionViewDataSource>
@property(nonatomic, strong) NSArray *items;
@property(nonatomic, copy) NKCollectionCellConfigurationBlock cellConfigurationBlock;
- (instancetype)init __attribute__((unavailable("Method is not available. Use initializers with parameters")));
@nik123
nik123 / NKTableViewArrayDataSource.h
Last active December 20, 2017 15:33
Array data source for table view
#import <UIKit/UIKit.h>
typedef void (^NKTableCellConfigurationBlock)(__kindof UITableViewCell *cell, id item);
@interface NKTableViewArrayDataSource : NSObject <UITableViewDataSource>
@property(strong, nonatomic) NSArray *items;
@property(strong, nonatomic) NKTableCellConfigurationBlock cellConfigurationBlock;
- (instancetype)init __attribute__((unavailable("Method is not available. Use factory method instead")));
@nik123
nik123 / CodableSample.swift
Last active March 21, 2018 15:52
Usage of Codable protocol in Swift 4
import UIKit
let gistJson = """
{
"id": "a366b9f5f87306e715fbbeeb7db5051f",
"description": "Objective-C: Availability API ",
"url": "https://api.github.com/gists/a366b9f5f87306e715fbbeeb7db5051f",
"created_at": "2017-10-27T10:53:25Z",
"updated_at": "2017-10-27T10:53:25Z",
"files": {
@nik123
nik123 / UIColor+HexColor.swift
Last active November 18, 2017 10:37
Convert a hex color string to a UIColor in Swift
import UIKit
extension UIColor {
/**
Create UIColor using hexString.
Acceptable format is "#RRGGBBAA" where:
- RR - hexadecimal value for red color. Required
- GG - hexadecimal value for green color. Required.
- BB - hexadecimal value for blue color. Required.