Skip to content

Instantly share code, notes, and snippets.

View treystout's full-sized avatar

Trey Stout treystout

  • Incyte Studios, LLC
  • OKC, OK
View GitHub Profile
@treystout
treystout / sets.py
Created August 2, 2012 21:26
General purpose-ish zset combiner for redis
#!/usr/bin/env python
import lib.akn.config as cfg
cfg.init(False)
from lib.akn.exceptions import CallError
def __zset_fetch(bind_pairs, start=0, end=29, count=False,
reverse=True, ids_only=False, operator="union", **kwargs):
"""General purpose tool for doing zset traversal in redis without abusing
local memory too much. To call it, you send in pairs consisting of
* a string representing a zset's key
@treystout
treystout / sets.py
Created August 2, 2012 21:28
General purpose zset union/intersect code (probably too meta)
#!/usr/bin/env python
import lib.akn.config as cfg
cfg.init(False)
from lib.akn.exceptions import CallError
def __zset_fetch(bind_pairs, start=0, end=29, count=False,
reverse=True, ids_only=False, operator="union", **kwargs):
"""General purpose tool for doing zset traversal in redis without abusing
local memory too much. To call it, you send in pairs consisting of
* a string representing a zset's key
@treystout
treystout / sets.py
Created August 2, 2012 21:28
General purpose zset union/intersect code (probably too meta)
#!/usr/bin/env python
import hashlib
import lib.akn.config as cfg
cfg.init(False)
from lib.akn.exceptions import CallError
def __zset_fetch(bind_pairs, start=0, end=29, count=False,
reverse=True, ids_only=False, operator="union", ttl=0, **kwargs):
"""General purpose tool for doing zset traversal in redis without abusing
local memory too much. To call it, you send in pairs consisting of
@treystout
treystout / gist:4178879
Created November 30, 2012 21:42
Forcing login
diff -r ffa320b5e178 web/site/auth.py
--- a/web/site/auth.py Thu Nov 29 15:47:01 2012 -0500
+++ b/web/site/auth.py Fri Nov 30 16:41:17 2012 -0500
@@ -5,12 +5,11 @@
Date Added: Fri Mar 23 20:08:15 PDT 2012
"""
import logging
+from functools import partial
-from flask import request as R, render_template as T, redirect, flash, \
@treystout
treystout / gist:4612305
Created January 23, 2013 19:58
the actual regex is wrong (only matches first char), but it does load and compile
604 19:56:24 vagrant@trey-vagrant [~/real_outland] J:0 (outland_env) [back_to_sql] ⎆ cat regex.yaml
regex: '[a-z0-9\.-_]'
605 19:56:28 vagrant@trey-vagrant [~/real_outland] J:0 (outland_env) [back_to_sql] ⎆ bpython
>>> import re, yaml
>>> y = yaml.load(open('regex.yaml'))
>>> y
{'regex': '[a-z0-9\\.-_]'}
>>> r = re.compile(y['regex'])
>>> r.match('trey')
<_sre.SRE_Match object at 0x21a2d98>
@treystout
treystout / phrase_finder.py
Created January 22, 2014 18:43
A shot at finding smallest substring of a larger string containing all words in the needle phrase
#!/usr/bin/env python
"""phrase_finder.py
Find the shortest segment of haystack text containing ALL of the needle words
SOME LICENSE BLAH BLAH...
Author: Trey Stout <treystout@gmail.com>
"""
import itertools
@treystout
treystout / phrase_finder.py
Created January 23, 2014 15:05
Revamped the algo to only go through haystack a single time. All segment detection is then done using a single word-location index. It sort of inch-worms down the haystack, marking valid "contractions" then returns the shortest one found.
#!/usr/bin/env python
"""phrase_finder.py
Find the shortest segment of haystack text containing ALL of the needle words
SOME LICENSE BLAH BLAH...
Author: Trey Stout <treystout@gmail.com>
"""
import collections
#!/usr/bin/env python
import sys
import string
from collections import deque, defaultdict
def findTerm( search, text ):
# Unique set of search terms (lowercase)
terms = set( s for s in search.lower().split(" ") )
/**
* Config was created in XVM Editor v0.71
* at Tue Jan 21 11:09:13 GMT-0500 2014
*/
{
"configVersion": "5.0.0",
"editorVersion": "0.71",
"definition": {
"author": "XVM",
"date": "03.11.2013",
def __update_generic(something, some_id, some_val):
rows = 0
with pool.cursor() as c:
rows = c.execute("UPDATE products SET %s=%%s WHERE product_id=%%s" %
something, (some_val, some_id))
return rows
set_description = partial(__update_generic, 'description')
set_materials = partial(__update_generic, 'materials')
set_price = partial(__update_generic, 'price_usd')