Skip to content

Instantly share code, notes, and snippets.

View mattpap's full-sized avatar

Mateusz Paprocki mattpap

  • Anaconda, Inc.
  • Wrocław, Poland
View GitHub Profile
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Categorical Axes</title>
<link rel="stylesheet" href="bokehjs/build/css/bokeh.css" type="text/css" />
<link rel="stylesheet" href="bokehjs/build/css/bokeh-widgets.css" type="text/css" />
<script type="text/javascript" src="bokehjs/build/js/bokeh.js"></script>
<script type="text/javascript" src="bokehjs/build/js/bokeh-api.js"></script>
<script type="text/javascript" src="bokehjs/build/js/bokeh-widgets.js"></script>
@mattpap
mattpap / cycle_tabs.py
Created March 30, 2018 20:54
Cycle bokeh's tabs with CustomJS
from bokeh.io import save
from bokeh.plotting import figure
from bokeh.layouts import column
from bokeh.models import CustomJS
from bokeh.models.widgets import Button, Tabs, Panel
def make_tab(color):
p = figure()
p.scatter([0], [0], color=color, radius=1)
return Panel(title="Tab: %s" % color.capitalize(), child=p)
from bokeh.core.properties import String, Instance
from bokeh.models import LayoutDOM, Slider
CODE ="""
import {div, empty} from "core/dom"
import * as p from "core/properties"
import {LayoutDOM, LayoutDOMView} from "models/layouts/layout_dom"
export class CustomView extends LayoutDOMView {
@mattpap
mattpap / linked_hover.py
Created May 4, 2016 12:11
Show how to connect two bokeh plots with hover tool
import numpy as np
from bokeh.plotting import figure, hplot, show, output_file
from bokeh.models import HoverTool, CustomJS, ColumnDataSource
N = 20
x = np.random.random(size=N)
y = np.random.random(size=N)
p = figure(tools=["hover"], toolbar_location=None)
@mattpap
mattpap / conway.py
Created May 2, 2016 14:39
Game of life in bokeh
# Run `bin/bokeh serve` and in a new terminal run `python conway.py`.
# Based on https://github.com/thearn/game-of-life.
from bokeh.plotting import figure, curdoc
from bokeh.client import push_session
from numpy.fft import fft2, ifft2, fftshift
import numpy as np
def fft_convolve2d(x,y):
@mattpap
mattpap / gist:c59ed5529744c06f23b1
Created November 10, 2014 12:23
Simplification using multiset_partitions()
In [1]: var('x1,x2,y1,y2,r1,r2')
Out[1]: (x₁, x₂, y₁, y₂, r₁, r₂)
In [2]: E=1/(2*x1**2 - 4*x1*x2 + 2*x2**2 + 2*y1**2 - 4*y1*y2 + 2*y2**2) * (-y1*r1**2 + y2*r1**2 + y1*r2**2 - y2*r2**2 + y1*x1**2 + y2*x1**2 - 2*x1*x2*y1 - 2*x1*x2*y2 + y1*x2**2 + y2*x2**2 + y1**3 - y2*y1**2 - y1*y2**2 + y2**3)
In [3]: n, d = E.as_numer_denom()
In [4]: _, D = factor(d).as_coeff_Mul()
In [5]: D
In [1]: from sympy.integrals.heurisch import heurisch
In [2]: f = 1/((sin(x)+cos(x)+1)**2)
In [3]: heurisch(f, x)
Out[3]:
2
⎛ ⎛x⎞ ⎞ ⎛x⎞ ⎛ ⎛x⎞ ⎞ ⎛x⎞ ⎛x⎞
2⋅log⎜tan⎜─⎟ + 1⎟⋅tan⎜─⎟ 2⋅log⎜tan⎜─⎟ + 1⎟ tan ⎜─⎟ 3⋅tan⎜─⎟
⎝ ⎝2⎠ ⎠ ⎝2⎠ ⎝ ⎝2⎠ ⎠ ⎝2⎠ ⎝2⎠
@mattpap
mattpap / gist:1285687
Created October 13, 2011 22:08
Solve
In [1]: [-sqrt(x)*sqrt(log((log(2) + I*pi)/log(2))),
...: sqrt(x)*sqrt(log((log(2) + I*pi)/log(2)))]
Out[1]:
⎡ ___________________ ___________________⎤
⎢ ___ ╱ ⎛log(2) + ⅈ⋅π⎞ ___ ╱ ⎛log(2) + ⅈ⋅π⎞ ⎥
⎢-╲╱ x ⋅ ╱ log⎜────────────⎟ , ╲╱ x ⋅ ╱ log⎜────────────⎟ ⎥
⎣ ╲╱ ⎝ log(2) ⎠ ╲╱ ⎝ log(2) ⎠ ⎦
In [2]: [-sqrt(x)*sqrt(-log(log(2)) + log(log(2) + I*pi)),
...: sqrt(x)*sqrt(-log(log(2)) + log(log(2) + I*pi))]
diff --git a/sympy/core/add.py b/sympy/core/add.py
index c20c76b..a2d274e 100644
--- a/sympy/core/add.py
+++ b/sympy/core/add.py
@@ -542,22 +542,26 @@ def primitive(self):
(1, 2*x/3 + 4.1*y)
"""
+ terms = [ arg.as_coeff_Mul() for arg in self.args ]
cont = S.Zero