Skip to content

Instantly share code, notes, and snippets.

View bgbg's full-sized avatar

Boris Gorelik bgbg

View GitHub Profile
@bgbg
bgbg / gist:2659700
Created May 11, 2012 13:39
Don't generate list of python mutables using "*" operator
>>> m = [[]] * 10
>>> m
[[], [], [], [], [], [], [], [], [], []]
>>> #everything seems to be OK
...
>>> m[0].append(10)
>>> m
[[10], [10], [10], [10], [10], [10], [10], [10], [10], [10]]
>>> #shit!
...
@bgbg
bgbg / tictoc.py
Created January 6, 2016 08:40
A simple stopwatch object that mimics Matlab's tic - toc pair
import time
class TicToc:
""" A simple stopwatch object"""
def __init__(self, name=None, start=True):
if name is None:
name = 'Running time'
self.name = name
self.dt = 0.0
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@bgbg
bgbg / another_triple_apply_pecularity.ipynb
Last active February 2, 2016 09:34
Another triple_apply pecularity
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@bgbg
bgbg / holidays_in_tishrei.ipynb
Last active August 24, 2021 08:00
holidays_in_tishrei.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@bgbg
bgbg / israeli_gender_payment_gap.ipynb
Created February 7, 2018 12:16 — forked from anonymous/israeli_gender_payment_gap.ipynb
israeli_gender_payment_gap.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@bgbg
bgbg / monty_hall.ipynb
Created February 7, 2018 12:21 — forked from anonymous/monty_hall.ipynb
monty_hall.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@bgbg
bgbg / asciihist.py
Last active August 17, 2023 09:34
ASCII histograms
from __future__ import print_function
import numpy as np
def asciihist(it, bins=10, minmax=None, str_tag='',
scale_output=30, generate_only=False, print_function=print):
"""Create an ASCII histogram from an interable of numbers.
Author: Boris Gorelik boris@gorelik.net. based on http://econpy.googlecode.com/svn/trunk/pytrix/pytrix.py
License: MIT
"""
ret = []
np.random.seed(123456)
N = 100
aim = 0
scale = 0.5
adjusted = []
for i in range(N):
curr = np.random.randn() * scale + aim
adjusted.append(curr)
aim = -curr
non_adjusted = np.random.randn(N)*scale
@bgbg
bgbg / emphasizing in graphs.ipynb
Last active November 12, 2018 18:53
Untitled.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.