Skip to content

Instantly share code, notes, and snippets.

@bhtucker
bhtucker / scenes.py
Created April 13, 2016 17:03
adventure game sketch
import random
GEORGI_TEXT = """
GEORGI IS HERE!!!!
Maybe you should [C]all for help.
"""
class Scene(object):
@bhtucker
bhtucker / markov_gist.py
Created April 7, 2016 21:21
Example Markov-chain-from-gutenberg-textfile implementation
# -*- coding: utf-8 -*-
"""
markov_generator_pipeline
~~~~~~~~~~~~~~~~~~~~~~~~~
An example markov generator that reads corpus one line at a time
and uses numpy for storing / drawing word likelihoods
Example source text:
http://www.gutenberg.org/cache/epub/28339/pg28339.txt
@bhtucker
bhtucker / main.py
Last active April 7, 2020 20:03
Demonstrate flush / rollback to handle database state
from flask import Flask, jsonify
from flask_sqlalchemy import SQLAlchemy
app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'postgresql://test@localhost/test'
db = SQLAlchemy(app)
db.init_app(app)
class User(db.Model):
@bhtucker
bhtucker / foobar.py
Created March 31, 2016 18:58
Sharing memory across uwsgi workers
"""
Simple worker showing different worker ids sharing/incrementing the same memory region
uwsgi --http :9090 --wsgi-file foobar.py --master --processes 4 --threads 2 --stats 127.0.0.1:9191 --sharedarea 2
Then just keep refreshing localhost:9090
"""
import uwsgi
INT_ORDS = {48, 49, 50, 51, 52, 53, 54, 55, 56, 57}