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 / chapters.gql
Created September 16, 2020 15:23
GQL query re-use
query LIST_ALL_MEMBERS(
$chapter_id: Int!,
$limit: Int = 20,
$offset: Int = 0
) {
users:chapter_members(
where: {
_and: [
{chapter_id: {_eq: $chapter_id}},
{is_chapter_organizer: {_eq: false}}
class AccessorDict(dict):
def __getitem__(self, key):
"""Handle access like foo['bar']
Wrap any raw dicts in new AccessorDict instances
"""
out = super(AccessorDict, self).__getitem__(key)
if isinstance(out, dict):
out = AccessorDict(out)
return out
#!/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(" ") )
@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
@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 / 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 / generate_handwriting_samples.py
Created December 7, 2015 21:37
Generates a PNG of every handwriting from Handwriting.io
#!/usr/bin/env python
"""This script simply renders a message as a pdf and saves it to a file
(out.pdf) in the working directory
"""
import os
import sys
try:
import requests
@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 / 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 / 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