Skip to content

Instantly share code, notes, and snippets.

View 2torus's full-sized avatar

Boris Ettinger 2torus

  • Tel Aviv, Israel
View GitHub Profile
@2torus
2torus / eu_membership.py
Last active November 11, 2023 17:08
Compute EU membership on a given date with Python by using data from Wikipedia
import pandas as pd
from datetime import date
from typing import List
from functools import cache
from warnings import warn
import re
MEMBERSHIP_URL = 'https://en.wikipedia.org/wiki/Member_state_of_the_European_Union'
MEMBERSHIP_URL_PERM_LINK = 'https://en.wikipedia.org/w/index.php?title=Member_state_of_the_European_Union&oldid=1184106841'
CANONICAL_WIKI_DATE = date(2023, 11, 11)
@2torus
2torus / bokeh_us_states_viz.py
Created May 15, 2022 15:02
Plot US states outlines in Bokeh
import json
from bokeh.io import output_notebook
from bokeh.plotting import figure, show, ColumnDataSource
from bokeh.models import GeoJSONDataSource
output_notebook()
# If you don't have the file yet
import requests as rq
@2torus
2torus / print-channel.clj
Last active May 19, 2021 19:06
Print channel, a channel that prints whatever is in the input and puts it back to output.
(require '[clojure.core.async :refer [chan, go, <!, >!, >!!, <!!]])
;=> nil
(defn print-channel
[channel-msg in]
(let [out (chan 1)]
(go (let [msg (<! in)]
((println channel-msg msg)
(>! out msg))))
out
))
# gpu info as a dict
# from https://gist.github.com/takuseno/2958caf1cb5e74314a9b5971999182b2
from subprocess import Popen, PIPE
from xml.etree.ElementTree import fromstring
def nvidia_smi_xml():
p = Popen(['nvidia-smi', '-q', '-x'], stdout=PIPE)
outs, errors = p.communicate()
return fromstring(outs)
@2torus
2torus / monitor_notebooks.py
Last active July 1, 2022 07:09
Get operating system information about jupyter notebooks from https://stackoverflow.com/a/44936664/996379
"""
Prints notebook's pid, memory and gpu memory utilization
The code is from https://stackoverflow.com/a/44936664/996379
Also gpu code is from https://gist.github.com/takuseno/2958caf1cb5e74314a9b5971999182b2
Usage:
python monitor_notebooks.py $notebook_token
if token is not supplied, it will prompt you for a token.
"""
import os
import os.path
@2torus
2torus / Dockerfile
Created September 3, 2020 07:23
Compares pandas_market_calendars versions
from python
RUN pip install pandas > /dev/null
ARG NEW="false"
RUN if [ ${NEW} = "true" ]; then pip install git+https://github.com/2torus/pandas_market_calendars.git@cache-holidays > /dev/null; else pip install pandas_market_calendars==1.4.2 > /dev/null; fi
RUN echo "import pandas as pd \n\
from random import sample, seed \n\
import time \n\
random_dates = pd.date_range('2000-1-1', '2019-1-1', freq='D') \n\
seed(0xDEED) \n\
random_dates = sample(random_dates.to_list(), 101) \n\
@2torus
2torus / ex2_18.erl
Created May 10, 2020 20:12
Exercise 2.18 of FutureLearn Erlang
-module(ex2_18).
-export([double/1, filter/1, median/1, modes/1]).
% tail recursive solutions, so they need reverse
% there is probably a library function for that.
reverse([], S) -> S;
reverse([X|Xs], S) -> reverse(Xs, [X|S]).
double(X) -> reverse(double(X,[]), []).
double([], L) -> L;
@2torus
2torus / ex2_15.erl
Last active May 11, 2020 07:31
Exercise 2.15 of FutureLearn class on Erlang
-module(ex2_15).
-export([prod/1, prod_tail/1, maxx/1, max_tail/1]).
prod([]) -> 1;
prod([X|Xs]) -> X * prod(Xs).
prod_tail(X) -> prod_tail(X, 1).
prod_tail([], P) -> P;
prod_tail([X|Xs], P) -> prod_tail(Xs, X * P).
@2torus
2torus / ex2.erl
Last active May 7, 2020 13:51
Second exercise in "Future Learn/Programming Erlang".
-module(ex2).
-export([max_three/3, how_many_equal/3, how_many_equal_test/0, xor1/2, xor2/2, xor3/2]).
xor1(true, B) ->
not B;
xor1(_, B) ->
B.
@2torus
2torus / first.erl
Created May 7, 2020 09:00
Programming exercise for "FutureLearn/Programming in Earlang"
-module(first).
-export([double/1, treble/1, square/1,perimeter/3, area/3]).
mult(X, Y) ->
X * Y.
double(X) ->
mult(2,X).
treble(X) ->
mult(3, X).
square(X) ->