Skip to content

Instantly share code, notes, and snippets.

Lev E. Givon lebedov

Block or report user

Report or block lebedov

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@lebedov
lebedov / jpype_api_demo.py
Last active Aug 4, 2019
How to call pdfbox's API with JPype.
View jpype_api_demo.py
#!/usr/bin/env python3
"""
How to call pdfbox's API with JPype.
"""
import jpype
import jpype.imports
import numpy as np
@lebedov
lebedov / pytorch_get_used_mem.py
Created Jun 24, 2019
Compute total memory consumed by PyTorch tensors
View pytorch_get_used_mem.py
#!/usr/bin/env python3
"""
Compute total memory consumed by PyTorch tensors.
"""
import gc
import torch
@lebedov
lebedov / .bashrc
Created May 2, 2019
Bash tab completion of environment names when using conda activate
View .bashrc
#!/bin/bash
# Add the following lines to .bashrc to enable tab completion of available conda
# environment names when using conda activate. Assumes conda and jq are in one's PATH:
export CONDA_ENV_LIST=`conda env list --json | jq -r '[ .envs[1:][] | split("/")[-1] ] | join(" ")'`
complete -W "$CONDA_ENV_LIST" conda activate
@lebedov
lebedov / nbshow-colorize.py
Created Feb 26, 2019
Add syntax highlighting to nbshow output.
View nbshow-colorize.py
#!/usr/bin/env python
"""
Add syntax highlighting to nbshow output.
"""
import argparse
import re
import pygments
@lebedov
lebedov / panel_boundedintinput.ipynb
Created Jan 7, 2019
Panel integer input widget with bounds
View panel_boundedintinput.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@lebedov
lebedov / ri2py_recursive.py
Created Nov 1, 2018
Recursively convert rpy2 objects to nested Python data structures.
View ri2py_recursive.py
#!/usr/bin/env python3
"""
Recursively convert rpy2 objects to nested Python data structures.
"""
import numpy as np
from rpy2.robjects import default_converter, globalenv, \
NULL, numpy2ri, pandas2ri, ListVector, r
@lebedov
lebedov / multi_video_reader.py
Created Jul 25, 2018
Class that provides an ImageIO-like interface to a sequence of videos treated as a single video.
View multi_video_reader.py
#!/usr/bin/env python3
"""
Class that provides an ImageIO-like interface to a sequence of videos treated as a single video.
"""
import bisect
import copy
import itertools
@lebedov
lebedov / find_lub_index_cumsum.py
Created Jul 25, 2018
Given a list of integers, determine the index of the least upper bound of some value that is in the cumulative sum array of the list.
View find_lub_index_cumsum.py
import bisect
import itertools
def find_lub_cumsum_index(a, x):
a_cumsum = list(itertools.accumulate(a))
i = bisect.bisect_right(a_cumsum, x)
if i != len(a):
return i
raise ValueError
@lebedov
lebedov / browse_video.py
Created May 31, 2018
Display movie file with support for browsing forward and backward through frames with a slider or arrow keys.
View browse_video.py
#!/usr/bin/env python3
"""
Display movie file with support for browsing forward and backward through frames
with a slider or arrow keys.
"""
import argparse
import datetime
import os
@lebedov
lebedov / pytorch_compute_out_size.py
Created Jun 30, 2017
Compute pytorch network layer output size given an input.
View pytorch_compute_out_size.py
#!/usr/bin/env python
"""
Compute pytorch network layer output size given an input.
"""
import numpy as np
import torch
import torch.autograd as autograd
import torch.nn as nn
You can’t perform that action at this time.