- We are writing a digital textbook-reading app.
- Most of the time you have a "basic" license for your textbook, but one (and only one) of your computers can request an "enhanced" license.
- You can only print from the computer with the enhanced license.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Simple LL(1) lexer and parser for a random data structure | |
# Based on description on book Language Implementation Patterns | |
class Lexer(object): | |
WS, NAME, STRING, NUM, LBRACK, RBRACK, LBRACE, RBRACE, COMMA, EQUAL, COMMENT,END = range(12); | |
EOF = '' # StringIO gives '' when nothing to read | |
def __init__(self, inio): | |
self.inio = inio | |
self.consume() | |
def consume(self): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# LR Parser using PLY | |
from sys import exit | |
import ply.lex as lex | |
import ply.yacc as yacc | |
from pprint import pprint | |
tokens = ( | |
'NAME', | |
'STRING', | |
'NUM', |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# PEG parser using parsimonious | |
from parsimonious.grammar import Grammar | |
from pprint import pprint | |
# MUST USE " - double quote in regex literal or gave very strange error messagas | |
# comment handling seems very difficult... | |
grammar = Grammar( | |
''' | |
record = name "=" value | |
name = _ ~"\w+" _ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# simple mocking rest api with file based storage | |
import json | |
from datetime import datetime, timedelta | |
from time import mktime | |
from bottle import * | |
tabs = ('users', 'biddings', 'auctions') | |
for tab in tabs: | |
globals()[tab] = [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# http://www.reddit.com/r/dailyprogrammer/comments/1g7gyi/061213_challenge_128_intermediate_covering/ | |
# attemp to use scipy.optimize to do this | |
import numpy as np | |
from StringIO import StringIO | |
from scipy.optimize import minimize | |
def solve(s): | |
f = StringIO(s) | |
data = np.loadtxt(f, dtype=np.uint8, skiprows=1) | |
n = data.shape[0] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <cstddef> | |
#include <iostream> | |
#include <string> | |
#include <functional> | |
#include <cassert> | |
using namespace std; | |
template<class T> | |
class HashMap | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <cassert> | |
#include <iostream> | |
#include <map> | |
#include <string> | |
using namespace std; | |
template<class K, class V> | |
class cache | |
{ | |
private: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
template<class T> | |
class Smart | |
{ | |
private: | |
struct Body | |
{ | |
T *ptr; |
OlderNewer