Skip to content

Instantly share code, notes, and snippets.

View cowlicks's full-sized avatar
💭
SEE TRANSLATION

cowlicks

💭
SEE TRANSLATION
View GitHub Profile
@cowlicks
cowlicks / monte-carlo-pi.py
Last active August 29, 2015 13:55
Monte Carlo estimation of pi using distarray
"""
Estimate pi using a Monte Carlo method.
If we imagine a unit circle inscribed within a unit square, the ratio of
the area of the circle to the area of the square is pi/4. So if a point
is chosen at random within the square, it has a pi/4 probability of
being inside the circle too.
So we choose one N points in the square, count how many are in the
circle and divide by N to give an estimation of pi/4. We then multiply
@cowlicks
cowlicks / wat.py
Created February 7, 2014 22:12
This should draw an evenly spaced grid. But it doesn't. So there is either a problem with distarray's maps, tondarray, or my logic.
"""
Calculate the Julia set for a given z <- z**2 + c with
IPython.parallel passed via command line args. Usage:
$ python julia_ipython.py <c real component> <c imaginary component>
"""
from IPython.parallel import Client
from matplotlib import pyplot
from distarray.client import Context
@cowlicks
cowlicks / pep0263.sh
Created February 19, 2014 17:14
pep0263 checker
#!/usr/bin/env bash
# Return a list of files which need to have the pep0263 encoding
# statement added.
PATTERN='coding: utf-8' # The pattern for your encoding
FILES=`find . -name "*.py"` # The files you want to check
for i in $FILES; do
# Get the line numbers matching the pattern
LINE=`grep -nr "$PATTERN" "$i" | cut -d : -f 2`

ufuncs

We have basic functionality but no axis arguments or broadcasting

random

???

Array Methods

@cowlicks
cowlicks / ipcluster_config.py
Created May 7, 2014 20:22
ipcluster config file for ipython
# Configuration file for ipcluster.
c = get_config()
c.IPClusterEngines.engine_launcher_class = 'SSH'
c.IPClusterEngines.controller_launcher_class = 'SSH'
c.SSHClusterLauncher.username = 'blake'
c.SSHClusterLauncher.hostname = '10.7.0.121'
c.SSHControllerLauncher.controller_cmd = ['/home/blake/.virtualenvs/remote-ipython-worker/bin/python', '-m', 'IPython.parallel.controller']
c.SSHEngineLauncher.engine_cmd = ['/home/blake/.virtualenvs/remote-ipython-worker/bin/python', '-m', 'IPython.parallel.engine']
c.SSHEngineSetLauncher.engine_cmd = ['/home/blake/.virtualenvs/remote-ipython-worker/bin/python', '-m', 'IPython.parallel.engine']
@cowlicks
cowlicks / eval_sucks.py
Created May 15, 2014 20:20
Why doesn't eval work here?
In [11]: def foo():
....: return b
....:
In [12]: eval('foo()', dict({'b':42}, **globals()))
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-12-a2089cf14959> in <module>()
----> 1 eval('foo()', dict({'b':42}, **globals()))
@cowlicks
cowlicks / research_programmer_conv.markdown
Created July 8, 2014 20:33
Minutes from Programmers in Research: their place in Universities at SciPy 2014

discussion

Q: Where can I find jobs a research scientist? A: The army core of engineers is hiring. I write code there. A: I'm at UMich we have been discussing support for research. We they think we should help scientist write code. Historically research groups just had a random programmer that would do thing for them.

Q: Can you say more about how this works at UMich? A: Groups steal and borrow programmers from each other. But they have not

@cowlicks
cowlicks / teddy_grams.py
Created November 16, 2014 00:53
My solution to a code golf game at ATX 2600. I don't think imports were counted. I don't even remember the prompt ¯\_(ツ)_/¯
from sys import stdin as r
from sys import argv as a
from pprint import pprint as p
l=r.read()
n=int(a[1])
g=[l[i:i+n] for i in range(len(l)-n)]
p(sorted([(i,g.count(i))for i in set(g)],key=lambda x:x[1])[::-1])
@cowlicks
cowlicks / get_and_edit_ipython_profile.py
Created November 16, 2014 01:16
Script for doing some management task on an ipython cluster.
#!/usr/bin/env bash
scp -r 10.7.0.121:~/.ipython/profile_default ~/profile_default
sed -i 's/"ssh": "",/"ssh": "10.7.0.121",/g' ~/profile_default/security/ipcontroller-client.json
rm -rf ~/.ipython/profile_default.bak
mv ~/.ipython/profile_default ~/.ipython/profile_default.bak
mv ~/profile_default ~/.ipython
@cowlicks
cowlicks / sakurai_3-5.ipynb
Last active August 29, 2015 14:10
sakurai quantum mechanics 3.5 with sympy
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.