Using Python's built-in defaultdict we can easily define a tree data structure:
def tree(): return defaultdict(tree)That's it!
| """ | |
| Minimal character-level Vanilla RNN model. Written by Andrej Karpathy (@karpathy) | |
| BSD License | |
| """ | |
| import numpy as np | |
| # data I/O | |
| data = open('input.txt', 'r').read() # should be simple plain text file | |
| chars = list(set(data)) | |
| data_size, vocab_size = len(data), len(chars) |
| # United States of America Python Dictionary to translate States, | |
| # Districts & Territories to Two-Letter codes and vice versa. | |
| # | |
| # Canonical URL: https://gist.github.com/rogerallen/1583593 | |
| # | |
| # Dedicated to the public domain. To the extent possible under law, | |
| # Roger Allen has waived all copyright and related or neighboring | |
| # rights to this code. Data originally from Wikipedia at the url: | |
| # https://en.wikipedia.org/wiki/ISO_3166-2:US | |
| # |
Using Python's built-in defaultdict we can easily define a tree data structure:
def tree(): return defaultdict(tree)That's it!
SAM and BAM filtering one-liners
@author: David Fredman, david.fredmanAAAAAA@gmail.com (sans poly-A tail)
@dependencies: http://sourceforge.net/projects/bamtools/ and http://samtools.sourceforge.net/
Please extend with additional/faster/better solutions via a pull request!
BWA mapping (using piping for minimal disk I/O)
All requests start with this URL: https://eutils.ncbi.nlm.nih.gov/entrez/eutils/
%22 for “; %23 for #).Incorrect: &id=352, 25125, 234
Correct: &id=352,25125,234
| require "active_record" | |
| ActiveRecord::Base.establish_connection('postgres:///testing') | |
| ActiveRecord::Migration.verbose = false | |
| ActiveRecord::Migration.class_eval do | |
| create_table :played_quizzes, force: true do |t| | |
| t.integer :player_ids, array: true | |
| t.json :quiz_snapshot | |
| end |
| #!/usr/bin/env python | |
| """strip outputs from an IPython Notebook | |
| Opens a notebook, strips its output, and writes the outputless version to the original file. | |
| Useful mainly as a git filter or pre-commit hook for users who don't want to track output in VCS. | |
| This does mostly the same thing as the `Clear All Output` command in the notebook UI. | |
| LICENSE: Public Domain |
The following compares the output of several creative hash functions designed for human readability.
sha1's are merely used as arbitrary, longer, distributed input values.
| input | 1 word output | 2 word output | 3 word output |
|---|
| # Based on Waveshare's epd5in65f.py demo. Copyright notice at end. | |
| import sys | |
| import os | |
| picdir = os.path.join(os.path.dirname(os.path.dirname(os.path.realpath(__file__))), 'pic') | |
| libdir = os.path.join(os.path.dirname(os.path.dirname(os.path.realpath(__file__))), 'lib') | |
| if os.path.exists(libdir): | |
| sys.path.append(libdir) |
I recently built a small agent-based model using Python and wanted to visualize the model in action. But as much as Python is an ideal tool for scientific computation (numpy, scipy, matplotlib), it's not as good for dynamic visualization (pygame?).
You know what's a very mature and flexible tool for drawing graphics? The DOM! For simple graphics you can use HTML and CSS; for more complicated stuff you can use Canvas, SVG, or WebGL. There are countless frameworks, libraries, and tutorials to help you draw exactly what you need. In my case, this was the animation I wanted:
(Each row represents a "worker" in my model, and each rectangle represents a "task.")