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 / doctesting_decorator.py
Last active November 21, 2020 10:02
Replacement for ipython_doctester
"""
ipython_doctester module is outdated. I tried to replace its test function with the function below
Code is from https://stackoverflow.com/a/47590703/996379
"""
import doctest
import copy
def test(func):
'''
Use test as a decorator to a function with doctests in Jupyter notebook.
Run the cell to see the results of the doctests.
@2torus
2torus / cors-server.py
Created May 27, 2018 13:59
Python http.server answering pre-flighted CORS options requests
import http.server
"""
Original at https://gist.github.com/enjalot/2904124
"""
class CORSHTTPRequestHandler(http.server.SimpleHTTPRequestHandler):
def send_head(self):
"""Common code for GET and HEAD commands.
This sends the response code and MIME headers.
@2torus
2torus / ajax_source_table.py
Created May 27, 2018 15:05
Bokeh DataTable doesn't support AjaxDataSource
import numpy as np
from datetime import timedelta
from functools import update_wrapper, wraps
from math import sin
from random import random
from six import string_types
from bokeh.models.widgets import DataTable, TableColumn
from bokeh.plotting import figure, show, output_file
from bokeh.models.sources import AjaxDataSource
@2torus
2torus / sliders-standalone-code.py
Created July 9, 2018 20:00
Bokeh sliders example rewritten as a standalone document with js callbacks
''' Rewrite the basic sliders example as a standalone document with JavaScript callbacks.
Present an interactive function explorer with slider widgets.
Scrub the sliders to change the properties of the ``sin`` curve, or
type into the title text box to update the title of the plot.
Run example with python sliders-standalone-code.py
In this version, the callbacks are written as strings of JS code.
'''
@2torus
2torus / didWeWin.py
Created October 5, 2018 06:11
Determine if you won Lightricks datahack competition
import numpy as np
import pandas as pd
import requests
def didWeWin(team_name):
text = requests\
.get('https://raw.githubusercontent.com/Lightricks/datahack/master/leaderboard.md')\
.text\
.split("\n")
def get_line(line):
return list(map(lambda x:x.strip(), line.split("|")))
module type Numeric =
sig
type t
val (+) : t -> t -> t
val (-) : t -> t -> t
val ( * ): t -> t -> t
val (/): t -> t -> t
val c: float -> t
val abs: t -> float
end
@2torus
2torus / afinn3.py
Created April 3, 2020 10:44
AFINN sentiment analysis - conversion to Python 3 of the original
#!/usr/bin/python3
# (conversion to python 3 of https://gist.github.com/fnielsen/4183541)
# (originally entered at https://gist.github.com/1035399)
#
# License: GPLv3
#
# To download the AFINN word list do:
# wget http://www2.imm.dtu.dk/pubdb/views/edoc_download.php/6010/zip/imm6010.zip
# unzip imm6010.zip
#
@2torus
2torus / nested-tensor-cpu.dockerfile
Last active April 27, 2020 15:31
Create dockers for nestedtensor pytorch extension for varying size tensors
FROM ubuntu:18.04
# copies https://raw.githubusercontent.com/pytorch/pytorch/master/docker/pytorch/Dockerfile
ARG PYTHON_VERSION=3.6.10
ARG WITH_TORCHVISION=1
RUN apt-get update && apt-get install -y --no-install-recommends \
build-essential \
cmake \
git \
curl \
ca-certificates \
@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) ->
@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.