Skip to content

Instantly share code, notes, and snippets.

@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}
@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 / 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 / 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 / PyMC3_demo.ipynb
Created May 6, 2016 20:43
Notebook used during RC Data Science Fridays talk (5/6/2016)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@bhtucker
bhtucker / ladders.sql
Created June 1, 2016 15:10
Materialized view for debate league ladder rankings
create materialized view ladder as (
with
match_points as (
select
case ... end as aff_points,
case ... end as neg_points,
aff_id,
neg_id
),
@bhtucker
bhtucker / Three Python Plotting Options.ipynb
Created June 21, 2016 19:03
An intro to some easy, interactive data visualization tools
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@bhtucker
bhtucker / hogwild_logistic_reg.py
Last active April 23, 2019 22:51
Use a Hogwild-inspired algorithm to learn logistic regression over a sample dataset in parallel
"""
Demo of using Hogwild algorthim for parallel learning with shared memory
Uses sklearn's LogisticRegression for accuracy comparison
Output
('initial accuracy:', 0.45333333333333331)
worker 25974 score 0.93
worker 25975 score 0.92
worker 25976 score 0.88
worker 25974 score 0.94
@bhtucker
bhtucker / diehard_puzzle_solver.py
Created June 23, 2016 18:58
Strongly solving a puzzle through breadth-first search
"""
Implementation of the example from https://inst.eecs.berkeley.edu/~cs61c/fa14/projs/02/
"""
import operator
class Puzzle(object):
"""General game representation"""
def solution(self):
return Position(0)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.