Skip to content

Instantly share code, notes, and snippets.

@tgs
tgs / coursebuilder-bytecodecache-1.4.1.patch
Created August 5, 2013 21:44
Patch to Google Course Builder v1.4.1, adding caching of the bytecode of Jinja2 templates. Change to the root dir of your course builder installation and use patch -p2 < (this file)
diff --git a/coursebuilder/common/jinja_filters.py b/coursebuilder/common/jinja_filters.py
index 2bb6d17..a8a6261 100644
--- a/coursebuilder/common/jinja_filters.py
+++ b/coursebuilder/common/jinja_filters.py
@@ -17,8 +17,10 @@
__author__ = 'John Orr (jorr@google.com)'
import jinja2
+from jinja2.bccache import BytecodeCache
import safe_dom
@tgs
tgs / coursebuilder-bytecodecache-1.5.0.patch
Created August 5, 2013 21:56
Patch to Google Course Builder v1.5.0, adding caching of the bytecode of Jinja2 templates. Change to the root dir of your course builder installation and use patch -p2 < (this file). Version 1.5.1 will probably include this patch.
diff --git a/coursebuilder/common/jinja_utils.py b/coursebuilder/common/jinja_utils.py
index 9854a44..a5501e0 100644
--- a/coursebuilder/common/jinja_utils.py
+++ b/coursebuilder/common/jinja_utils.py
@@ -18,8 +18,10 @@ __author__ = 'John Orr (jorr@google.com)'
import jinja2
from webapp2_extras import i18n
+from models.models import MemcacheManager
import safe_dom
@tgs
tgs / ckbleach.py
Created November 22, 2013 18:47
Convert the specification of allowed tags, attributes, etc. for Python's Bleach module, into a list that CKEditor understands. This is useful because, if you don't tell CKEditor what tags it can use, it will likely use ones you don't want to allow through.
import StringIO
def allowed_content(tags, attributes={}, styles=()):
"""
Given a list of allowed tags, dict of allowed attributes, and list of
allowed styles, generates a CKEditor 'allowedcontent' string. The default
lists used by the bleach module are: bleach.ALLOWED_TAGS,
bleach.ALLOWED_ATTRIBUTES, and bleach.ALLOWED_STYLES (which is empty by
default). This function's defaults are all empty lists/dicts.
@tgs
tgs / appengine_bytecode_cache.py
Last active May 13, 2016 07:13
A version of Jinja2's MemcachedBytecodeCache with two extra features: support for namespaces, as used in Google App Engine's memcache module; and the ability to clear the cache.
from jinja2.bccache import BytecodeCache
__author__ = "Thomas Grenfell Smith (thomathom@gmail.com)"
class ClearableMemcachedBytecodeCache(BytecodeCache):
"""Requires a fancy memcache client, like Google App Engine's,
that supports namespaces. Requires get, set, add, and incr.
When you call .clear(), the entries previously stored through
this object become inaccessible through it, although they
@tgs
tgs / index.html
Last active November 13, 2017 21:27 — forked from hubgit/index.html
PubMed search with jQuery
<!doctype html>
<meta charset="utf-8">
<title>PubMed Search</title>
<link rel="stylesheet" href="https://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css">
<ul id="output"></ul>
<script src="https://code.jquery.com/jquery-2.1.1.min.js"></script>
<script src="pubmed-search.js"></script>
@tgs
tgs / poor_mans_hist3.matlab
Created March 23, 2011 20:49
Make a 2d or 3d histogram to visualize data density
% Code from http://goo.gl/lhXpN (Doug Hull's mathworks blog)
% With changes suggested by Andrea and Thomas in the comment thread
%
% See also "cloudplot":
% http://www.mathworks.com/matlabcentral/fileexchange/23238-cloudplot
% put your input data as vertical arrays in x and y
x = randn(100000,1);
y = randn(100000,1) * 20;
@tgs
tgs / logiq.py
Last active May 1, 2019 21:19
Prototype Python library for making error messages that explain complicated conditions
# This is a work-for-hire for the Government of the United States, so it is not
# subject to copyright protection.
"""
logiq - A way to build complex conditions and evaluate them against the world.
The goal is to make the conditions easy to construct, and give them useful and
concise error messages as well.
These are some requirement nodes:
@tgs
tgs / ncbi2na.py
Last active April 19, 2023 16:06
Translate NCBI2na data from hexadecimal to standard bases
#!/usr/bin/env python
"""
Translate compact hex sequence representation to standard bases.
If you have NCBI ASN.1 data, the easiest way to get a FASTA version is to
use NCBI's asn2fasta tool, which is available here:
https://ftp.ncbi.nlm.nih.gov/asn1-converters/by_program/asn2fasta/
NCBI2na is a compact representation of sequence data, where each base just
takes 2 bits. It's commonly found in text ASN.1 files as hexadecimal strings.