Skip to content

Instantly share code, notes, and snippets.

@ajp619
ajp619 / markdown_boxes.md
Created April 30, 2020 03:45
Create colored boxes in Jupyter notebooks
# vim binding
c.ZMQTerminalInteractiveShell.editing_mode='vi'
@ajp619
ajp619 / kw_decorator.py
Created October 20, 2017 22:33
python decorator to pre-populate key word arguments
def decorator_generator(**kw_dict):
def decorator(fun):
def decorated(*args, **kwargs):
kwargs.update(kw_dict)
return fun(*args, **kwargs)
return decorated
return decorator
@decorator_generator(c=3)
def foo(a, c):
@ajp619
ajp619 / matMult.txt
Last active August 14, 2017 21:08
Best way to multiply matrices in python
a = np.array([[1, 2, 3]])
np.mat(a) * np.mat(a).T # this can continue ...
@ajp619
ajp619 / beakerRunTag.html
Created August 10, 2016 17:15
Put this in a beaker notebook cell to have a button to run cells of a given tag.
<div>
<button onclick="evaluateTags(this.parentElement)"
style="background-color:lightgreen">Run cells with tag</button>
<!-- SET TAG NAME BELOW: value="tagName" -->
<input type=text value="tagName">
</div>
<script>
function evaluateTags(divElement) {
d3.select(divElement).select("button").attr("style", "background-color:indianred")
d3.select(divElement).selectAll("p").remove()
@ajp619
ajp619 / pyprint
Last active August 3, 2016 19:38
def pyprint(myfile, lexer_override=""):
from pygments import highlight
from pygments.lexers import PythonLexer, guess_lexer, get_lexer_by_name
from pygments.util import ClassNotFound
from pygments.formatters import HtmlFormatter
import IPython
try:
with open(myfile) as f:
code = f.read()
@ajp619
ajp619 / code_chunk_options.Rmd
Last active October 30, 2015 15:00
Useful code chunk options
Entire R script
'''{r code=capture.output(cat(readLines('clustering_library.R'), sep='\n'))}
'''
A single function
'''{r code=capture.output(dump('initBuckets', ''))}
'''
note: replaced back ticks with forward ticks so the options would show up instead of being hidden.
@ajp619
ajp619 / qtutil.py
Last active December 10, 2015 18:34
A silly utility to launch a qtconsole in an IPython Notebook if one doesn't already exist. Just put this in a cell.
# silly utility to launch a qtconsole if one doesn't exist
consoleFlag = True
consoleFlag = False # Turn on/off by commenting/uncommenting this line
import psutil
def returnPyIDs():
pyids = set()
for pid in psutil.pids():
---
title: "IS 609 Homework 4"
author: "Aaron Palumbo"
date: "Saturday, September 20, 2014"
output: pdf_document
---
Homework 4:
## Page 191: #3
@ajp619
ajp619 / poly.Rmd
Created April 19, 2014 05:00
R poly()
### poly
How does poly work?
```{r}
a <- 1:10
# Let's start easy
p <- poly(a, 3, raw=TRUE)
p
# This is easy to reproduce