- https://www.w3.org/2001/sw/sweo/public/UseCases/FAO/
- presentation on event in 2010
- Yummly food processor
- FOODpedia, linked data for food products
- Semantic web and GS1 (presentation)
- Example of how to use a semantic web of food
- OpenFoodFacts food product ontology notes, you can download a full products RDF dump
- Linked open data for halal food products - nice usage example
# File: KnuthMorrisPratt.py | |
# Author: Keith Schwarz (htiek@cs.stanford.edu) | |
# | |
# An implementation of the Knuth-Morris-Pratt (KMP) string-matching algorithm. | |
# This algorithm takes as input a pattern string P and target string T, then | |
# finds the first occurrence of the string T in the pattern P, doing so in time | |
# O(|P| + |T|). The logic behind the algorithm is not particularly complex, | |
# though getting it to run in linear time requires a few non-obvious tricks. | |
# | |
# To motivate KMP, consider the naive algorithm for trying to match a pattern |
The following are examples of the four types rate limiters discussed in the accompanying blog post. In the examples below I've used pseudocode-like Ruby, so if you're unfamiliar with Ruby you should be able to easily translate this approach to other languages. Complete examples in Ruby are also provided later in this gist.
In most cases you'll want all these examples to be classes, but I've used simple functions here to keep the code samples brief.
This uses a basic token bucket algorithm and relies on the fact that Redis scripts execute atomically. No other operations can run between fetching the count and writing the new count.
class Node(object): | |
def __init__(self, val): | |
self.val = val | |
self.left = None | |
self.right = None | |
self.height = 1 | |
class AVLTree(object): | |
def __init__(self): |
I liked the way Grokking the coding interview organized problems into learnable patterns. However, the course is expensive and the majority of the time the problems are copy-pasted from leetcode. As the explanations on leetcode are usually just as good, the course really boils down to being a glorified curated list of leetcode problems.
So below I made a list of leetcode problems that are as close to grokking problems as possible.
# Nathan Lehrer | |
def get_best_path(grid): | |
# Finds the best path through an M x N grid of point values, and that path's score | |
# Input: grid = grid of point values = M x N list of lists | |
# Returns: best_score = best possible score = int, path = best possible path = string | |
M,N = len(grid),len(grid[0]) | |
scores = {(0,0):grid[0][0]} # best score for a path to each cell; score of (0,0) is grid value | |
trace = {} # whether we optimally come from up ('U') or left ('L') into each cell | |
import collections | |
# 0 is water, 1 is land. | |
arr = [ | |
[0, 1, 0, 0, 0, 0, 1, 1, 1, 0, 0], | |
[0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0], | |
[0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0], | |
[0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0], | |
[0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0], |
gunicorn run:app --workers=9
gunicorn run:app --workers=9 --worker-class=meinheld.gmeinheld.MeinheldWorker
Macbook Pro 2015 Python 3.7
Framework | Server | Req/s | Max latency | +/- Stdev |
---|
This logging setup configures Structlog to output pretty logs in development, and JSON log lines in production.
Then, you can use Structlog loggers or standard logging
loggers, and they both will be processed by the Structlog pipeline (see the hello()
endpoint for reference). That way any log generated by your dependencies will also be processed and enriched, even if they know nothing about Structlog!
Requests are assigned a correlation ID with the asgi-correlation-id
middleware (either captured from incoming request or generated on the fly).
All logs are linked to the correlation ID, and to the Datadog trace/span if instrumented.
This data "global to the request" is stored in context vars, and automatically added to all logs produced during the request thanks to Structlog.
You can add to these "global local variables" at any point in an endpoint with `structlog.contextvars.bind_contextvars(custom