Skip to content

Instantly share code, notes, and snippets.

Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@philip-bl
philip-bl / .sh
Last active November 30, 2016 01:34
Custom bash prompt
# becomes red if previous command's result is not zero
# records time
# looks kinda nice
function red_if_nonzero {
RETVAL=$?; # get status code of the previously run command
[ $RETVAL -ne 0 ] && tput setaf 1; # if it's not 0, use color red
return 0;
}
@philip-bl
philip-bl / pandas_suck_no_create_index.ipynb
Created April 20, 2017 16:51
Pandas Suck. No CREATE INDEX
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
#include <cstddef>
#include <cstdint>
#include <list>
#include <vector>
#include <functional> // use std::hash<Key>
#include <memory> // unique_ptr
#include <stdexcept> // out_of_range
#include <iostream>
#include <string>
#include <unordered_map>
@philip-bl
philip-bl / .config-systemd-user-thyme.service
Last active February 4, 2018 00:19
Thyme helper scripts. I used dashes instead of slashes in filenames. Don't forget to create ~/logs/
# https://about.sourcegraph.com/blog/thyme-a-simple-cli-to-measure-human-time-and-focus/
# https://github.com/sourcegraph/thyme
[Unit]
Description=Call thyme to save windows usage to json for statistics
[Service]
Type=oneshot
ExecStart=/home/shibbiry/go/bin/thyme track -o /home/shibbiry/logs/thyme.json
# if thyme has not finished in 5 seconds, consider it failed and kill it
@philip-bl
philip-bl / shapy_linear.py
Created April 26, 2019 23:27
Linear layer for tensors of any shape in pytorch
class ShapyLinear(nn.Module):
"""Can model any affine function from the set of tensors of any (fixed) shape `in_shape` to
the set of tensors of any (fixed) shape `out_shape`.
In forward method the first modes of `inputs` are interpreted as indices of samples,
then come the modes corresponding to `in_shape`. The affine function is applied to each sample."""
def __init__(self, in_shape, out_shape):
""":param in_shape: shape of one input sample
:param out_shape: shape of one output sample"""
super().__init__()
def set_random_seeds(seed_value=555, device='cuda:0'):
'''source https://forums.fast.ai/t/solved-reproducibility-where-is-the-randomness-coming-in/31628/5.'''
np.random.seed(seed_value)
torch.manual_seed(seed_value)
random.seed(seed_value)
if device != 'cpu':
torch.cuda.manual_seed(seed_value)
torch.cuda.manual_seed_all(seed_value)
torch.backends.cudnn.deterministic = True
torch.backends.cudnn.benchmark = False
def free_cuda_memory():
import gc
gc.collect()
torch.cuda.empty_cache()
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.