Skip to content

Instantly share code, notes, and snippets.

View jasongrout's full-sized avatar

Jason Grout jasongrout

View GitHub Profile
@jasongrout
jasongrout / test.py
Created October 31, 2010 03:13
Test gist
# This is a test gist, just to see how this works.
a=3
for i in range(10):
x=3
print(x)
<html>
<head>
<title>test</title>
</head>
<body>
<h1>testing gist again</h1>
<script src="http://gist.github.com/3806.js"></script>
</body>
</html>
# Load a sparse matrix.
import numpy as np
from scipy import sparse
def mymethod():
print 'hi'
def load_sparse(filename, dtype=np.float32):
with file(filename) as input:
This is gist.
There are many like it, but this one is mine.
It is my life.
I must master it as I must master my life.
Without me gist is useless.
Without gist, I am useless.
import contextlib
@contextlib.contextmanager
def timing(results=None):
"""
Time the execution of the block of code. If a results list is
passed in, the time is appended to the list. Also returns a list
of one element containing the time the execution took.
To use, do something like:
class mydecorator(object):
def __init__(self, times, repeats):
self.times=times
self.repeats=repeats
self.a=1
def __call__(self, func):
# here, we just need to return a new function. That new function will be what is actually stored in the name and run when I.
def myfunc(*args, **kwargs):
# *this* inner function is what is actually called
@jasongrout
jasongrout / gist:1010165
Created June 6, 2011 12:33
Efficient sum that doesn't try to simplify in Sage
def fsum(x,a):
g(x) = 1/2
list_of_terms=[2*(((-1)^n-1)/(n*pi)^2*cos(n*pi*x)-(-1)^n/(n*pi)*sin(n*pi*x)) for n in [1..a]]
g += sum(list_of_terms)
return g
@jasongrout
jasongrout / myfile.sage
Created August 1, 2011 23:40
test sage code
print 'hi'
@jasongrout
jasongrout / embed_sage.html
Created August 2, 2011 16:08
Embed a single cell server in a web page
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-type" content="text/html;charset=UTF-8">
<meta name="viewport" content="width=device-width">
<title>Simple Compute Server</title>
<script type="text/javascript" src="http://sagemath.org:5467/static/jquery-1.5.min.js"></script>
<script type="text/javascript" src="http://sagemath.org:5467/embedded_singlecell.js"></script>
<script>
TEXT(<<'EOF');
<div id="singlecell-test"><script type="text/code">var('x')
x0 = 0
f(x) = sin(x)*e^(-x)
p = plot(f,(x,-1,5), thickness=2)
dot = point((x0,f(x=x0)),pointsize=80,rgbcolor=(1,0,0))
@interact
def _(order=(1..12)):
ft = f.taylor(x,x0,order)
pt = plot(ft,(x,-1, 5), color='green', thickness=2)