Skip to content

Instantly share code, notes, and snippets.

@app.route("/cart")
def shopping_cart():
"""TODO: Display the contents of the shopping cart. The shopping cart is a
list held in the session that contains all the melons to be added. Check
accompanying screenshots for details."""
melon_ids = session.get("my_melons")
melon_qty = {}
for melon_id in melon_ids:
if melon_qty.get(melon_id):
SQL> problem
Problem 2
Select statements can have an additional clause called the 'where' clause.
This lets us extract specific rows out of our table. Our where clause can be
specific enough to match a single row, or general enough to match a set of
rows. The format of a select statement with a 'where' clause is:
SELECT <column list> FROM <table name> WHERE <equality expression>;
Examples: http://sqlzoo.net/wiki/SELECT_basics -- 1
"Pathogen"
call pathogen#infect()
"Taglist stuff for mac"
let Tlist_Ctags_Cmd='/usr/local/bin/ctags'
"Basic crap for coding"
syntax on
set ai
set autochdir
Meringue:shenanigans chriszf$ python test.py
fish
this is a fish
s/"fish"/"squid"/g
squid
this is a squid
@chriszf
chriszf / gist:7435390
Created November 12, 2013 17:48
"Python needs to be more like vim" -- nobody anywhere, ever
Meringue:shenanigans chriszf$ python
Python 2.7.1 (r271:86832, Jun 25 2011, 05:09:01)
[GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.15.00)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import lib.vim
>>> some_str = "DevBeat is pretty alright"
>>> s/"alright"/"awesome"/some_str
'DevBeat is pretty awesome'
>>>
@chriszf
chriszf / gist:7427457
Created November 12, 2013 08:25
I thought python could use some new syntax...
mac3:shenanigans czf$ cat 031_switchcase2.py
import lib.switchcase
def one():
print "One branch executed"
def two():
print "Two branch executed"
def three():
import lib.switchcase
def one():
print "One branch executed"
def two():
print "Two branch executed"
def three():
print "Three branch executed"
def cross(A, B):
"Cross product of elements in A and elements in B."
return [a+b for a in A for b in B]
digits = '123456789'
rows = 'ABCDEFGHI'
cols = digits
squares = cross(rows, cols)
unitlist = ([cross(rows, c) for c in cols] +
[cross(r, cols) for r in rows] +
class case(object):
EMPTY_CASE = (None for x in [1])
def __init__(self, *args):
self.cases = args
self.used = False
def __iter__(self):
return self
def next(self):
@chriszf
chriszf / ex4
Created October 1, 2013 21:52
Exercise solutions
def custom_len(input_list):
"""custom_len(input_list) imitates len(input_list)"""
count = 0
for item in input_list:
count += 1
return count
def custom_remove(input_list, value):
"""custom_remove(input_list, value) imitates input_list.remove(value)"""
for i in range(custom_len(input_list)):