Skip to content

Instantly share code, notes, and snippets.

View davidism's full-sized avatar

David Lord davidism

View GitHub Profile
@davidism
davidism / cors_session.html
Last active March 11, 2022 17:23
Flask WTF CSRF with CORS
<!-- executing from http://localhost.localdomain:63342 -->
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
<script>
$.ajax({
url: 'http://localhost.localdomain:5000/',
xhrFields: {
withCredentials: true
},
success: function (data) {
$.post({
@davidism
davidism / bar6.py
Created September 22, 2016 20:05
Query drinks with both ingredients
import sqlalchemy as sa
from sqlalchemy import orm
from sqlalchemy.ext.associationproxy import association_proxy
from sqlalchemy.ext.declarative import declarative_base
engine = sa.create_engine('sqlite://', echo=True)
session = orm.Session(engine)
Base = declarative_base()
@davidism
davidism / class_scope.py
Created July 27, 2016 15:03
class namespace scope
a = 'global'
class Fred:
a = 'class'
b = (a for i in range(10))
c = [a for i in range(10)]
d = a
e = lambda: a
f = lambda a=a: a
@davidism
davidism / keybase.md
Created June 3, 2016 15:31
Keybase proof

Keybase proof

I hereby claim:

  • I am davidism on github.
  • I am davidism (https://keybase.io/davidism) on keybase.
  • I have a public key ASBDYLNew7drjvzVbNID47IlHGxdpsy1Z0Nzz8-GSIiaSAo

To claim this, I am signing this object:

@davidism
davidism / app.py
Created January 7, 2015 02:47
Flask session test
import sys
from flask import Flask, session, url_for, redirect
app = Flask(__name__)
app.secret_key = 'secret'
@app.route('/')
def set():
session.clear()
session['works'] = True
@davidism
davidism / salad.py
Last active December 15, 2019 02:24
Salad to English dictionary. Very, very simple MVC example.
# ================
# Models
# represents data that will be stored and retrieved
# normally would go in a database (see SQLAlchemy), here it's just some plain classes and dictionaries
# ================
class Word(object):
"""Represents a word in the Cabbage language and it's translation to English."""
def __init__(self, value, translation):
@davidism
davidism / nest.py
Created June 13, 2014 21:27
Build "path" by accessing attributes and calling
class NestMeta(type):
def __getattr__(cls, key):
return cls(cls, key)
def __str__(cls):
return cls.__name__
__repr__ = __str__