Skip to content

Instantly share code, notes, and snippets.

View caiw's full-sized avatar

Cai caiw

View GitHub Profile
import numpy as np
import numpy.linalg as la
from matplotlib import pyplot as pp
from sympy import factorint
def P(f,x,u,ax):
b=np.linspace(0,6,61)
if f<2:
s=la.norm(u)
ax.add_patch(pp.Polygon(np.transpose(np.concatenate([[x[0][0]+np.sin(b)*s],[x[1][0]+np.cos(b)*s]])),color='k',linewidth=0))
else:
@caiw
caiw / tumult_hype_deeplink.js
Last active June 23, 2018 19:54
Link to a specific scene in a Tumult Hype document
@caiw
caiw / correlation_bf.py
Last active November 15, 2017 14:42
Python port of Wetzels & Wagenmakers (2012) R code for calculating Bayes factors for (partial) correlation values
"""
Calculate the Bayes factor for (partial) correlation values using the JZS prior.
Ported from R code in Wetzels & Wagenmakers (2012) "A default Bayesian hypothesis test for correlations and partial
correlations". Psychon Bull Rev. 19:1057–1064 doi:10.3758/s13423-012-0295-x
"""
from math import sqrt, exp, gamma
from numpy import inf
from scipy import integrate
@caiw
caiw / seaborn_stacked_bar.py
Last active November 5, 2020 05:11 — forked from randyzwitch/seaborn-stacked-bar.py
Python Seaborn Stacked Bar Chart
"""
===========================
Stacked bar graph using seaborn.
Forked from: https://gist.github.com/randyzwitch/b71d47e0d380a1a6bef9
With extra inspiration from: https://gist.github.com/extrospective/0f4fe69304184d813f982035d9684452
===========================
"""
from matplotlib import pyplot
import seaborn
// http://cai.zone/2014/02/a-javascript-hack-to-have-spry-collapsiblepanels-remember-their-state/
// Assumes global object sessvars from sessvars.js
// http://www.thomasfrank.se/sessionvars.html
// You should include this right at the bottom of the html file containing the panels, like this:
// <!-- Wire panels -->
// <script type="text/javascript" src="spry-collapsiblepanels-remember-state.js"></script>
// And this should *replace* the javascript which Dreamweaver added to create the panels.
// http://cai.zone/2013/07/a-quick-javascript-hack-to-fake-adjustin-html5-audio-elements-timeupdate-event-frequency/
var audio_clock;
$(audiohtml).bind("timeupdate", onAudioUpdate);
$(audiohtml).bind("play", function(){
audio_clock = setInterval(function(){
onAudioUpdate();
}, 100);
});