Skip to content

Instantly share code, notes, and snippets.

{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"This is a test notebook!\n"
]
},
{
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@stober
stober / gp.py
Created February 16, 2013 00:17
Gaussian Process in Python
#!/usr/bin/python
"""
Author: Jeremy M. Stober
Program: GP.PY
Date: Thursday, July 17 2008
Description: Example of Gaussian Process Regression.
"""
from numpy import *
import pylab
@stober
stober / chunk.py
Created January 25, 2013 04:40
Slice indices for generating array chunks.
def chunk(n, nchunks):
"""Return a list of slices that divide an array into approximately nparts."""
d = n / nchunks
r = n - nchunks * d
indices = range(0,(d+1)*r,d+1) + range((d+1)*r, n+d, d)
indices[-1] = None
a,b = tee(indices)
next(b,None)
return izip(a,b)
@stober
stober / slug.py
Created January 18, 2013 19:46
A useful method to turn titles into slugs for urls. BSD code from deep in the heart of Django.
import re
import unicodedata
def slugify(value):
"""
Converts to lowercase, removes non-word characters (alphanumerics and
underscores) and converts spaces to hyphens. Also strips leading and
trailing whitespace.
"""
@stober
stober / static.py
Created August 30, 2012 17:41
A workaround for "static" variables in Python functions.
#!/usr/bin/env python
'''
@author jstober
'''
def test_static(static=[0]):
static[0] += 1
return static[0]
print test_static() # 1
@stober
stober / un_split_pane.py
Created August 23, 2012 22:36
Unsplit a pane.
import sublime, sublime_plugin
class UnSplitPaneCommand(sublime_plugin.WindowCommand):
def run(self):
if self.window.num_groups() == 2:
for view in self.window.views_in_group(1):
#TODO check modified?
self.window.focus_view(view)
self.window.run_command('close_file')
@stober
stober / split_pane.py
Created August 23, 2012 22:35
Split the view on a single file.
import sublime_plugin,sublime
class SplitPaneCommand(sublime_plugin.WindowCommand):
def run(self):
if self.window.num_groups() == 1:
self.window.run_command('set_layout',
{
"cols": [0.0, 0.5, 1.0],
"rows": [0.0, 1.0],
"cells": [[0, 0, 1, 1], [1, 0, 2, 1]]
@stober
stober / file_path.py
Created August 16, 2012 18:48
First Sublime Text Plugin
import sublime, sublime_plugin
class FilePathCommand(sublime_plugin.TextCommand):
""" Show the full file path in the status bar. """
def run(self, args):
sublime.status_message(self.view.file_name())
@stober
stober / hate.py
Created August 16, 2012 18:09
Small Python Hate Snippets
"""
Things I hate about Python.
"""
import distutils
try:
print distutils.sysconfig.get_python_lib()
except:
print "Failed call!"