Skip to content

Instantly share code, notes, and snippets.

@mbeltagy
mbeltagy / nonLinearHW9.1.ipynb
Last active April 14, 2017 22:09
Homework from complexity explore course.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@mbeltagy
mbeltagy / gist:129a584c21ce56ac3b60
Last active August 29, 2015 14:20
Monkeys and Coconuts
x=zeros(Float64,5)
maxmultiple=1000
for m=1:maxmultiple
x[5]=4*5*m #It has to be divisalbe by 4 and 5
for i=4:-1:1
x[i]=5x[i+1]/4+1
end
x0=x[1]*5/4+1
if isinteger(x)&&isinteger(x0)
println(int(x))
@mbeltagy
mbeltagy / RelMathinJulia.ipynb
Last active April 14, 2017 22:08
Analysis of the rate of growth of different relgions
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@mbeltagy
mbeltagy / gist:834988ba7b4c0eb69922
Created July 16, 2015 15:28
A pairs function in julia that uses PyPlot to generate plots similar to R's pairs
function pairs(d::DataFrame)
varnames= map(string,names(d))
l=length(varnames)
count=0
for i=1:l
for j=1:l
count+=1
ax=subplot(l,l,count)
ax[:xaxis][:set_visible](false)
ax[:yaxis][:set_visible](false)
@mbeltagy
mbeltagy / gist:a5f5657dc092c8b3cc78
Created July 16, 2015 16:03
Box plot on Data Frames
function dataframeplot(d::DataFrame,facsym,idsym)
factors=sort(unique(d[facsym])) #We need this to do the boxpols
numpoints=size(d,1)
numfactors=length(factors)
data=Array(Array{Float64},numfactors)
for i=1:numfactors data[i]=[] end
for i=1:numpoints
idvar=d[idsym][i]
fac=d[facsym][i]
for j=1:numfactors
@mbeltagy
mbeltagy / backgammon_prob.jl
Created October 19, 2015 18:40
Calculating the probability of getting a double dice to move peg to any particular point after where it is in game of backgammon.
function backgammon_prob()
location_hits=zeros(Int,24)
for i=1:6, j=1:6
if(i!=j) # to avoid double counting doubles
location_hits[i]+=1
location_hits[j]+=1
else
location_hits[j]+=1
end
location_hits[i+j]+=1
@mbeltagy
mbeltagy / Probability.ipynb
Last active October 26, 2016 07:59
Julia translation of Norvig's notebook on "Probability, Paradox, and the Reasonable Person Principle"
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@mbeltagy
mbeltagy / ErrorPropagation.ipynb
Created December 9, 2015 15:55
The error propagation enigma. Some problems are harder than they first appear
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@mbeltagy
mbeltagy / subfix.jl
Created June 4, 2016 01:20
Reading two subtitle files and harmonizing the times.
# This script fixes subtitle timing your timestamps
# from on file to adjust another
# Opening up the first file in swedish
using StringEncodings
open("The.Seventh.Seal.1957.PROPER.1080p.BluRay.x264-SADPANDA.srt") do io
global swe=readall(io,enc"ISO-8859-15")
end;
swesplit=matchall(r"(\d{1,4}\r\n\d.*?)(?=(\n\d|$))"s,swe);
# The second file in English
open("The\ Seventh\ Seal\ [Det\ Sjunde\ Inseglet].1957.BRRip.XviD.AC3-VLiS.srt") do io
@mbeltagy
mbeltagy / GMM_for_clustering.ipynb
Last active September 28, 2020 02:04
Using Gausian Mixtures in the Julia Package https://github.com/davidavdav/GaussianMixtures.jl for clustering.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.