Skip to content

Instantly share code, notes, and snippets.

View patkujawa-wf's full-sized avatar

Pat Kujawa patkujawa-wf

  • Workiva
  • Missoula, Montana, USA
View GitHub Profile
@patkujawa-wf
patkujawa-wf / cancellation_token.dart
Created September 26, 2018 03:29
Example CancellationToken[Source] a la .net. Provides a way to signal that an operation has been canceled
import 'package:w_common/func.dart';
/// Provides a way to signal that an operation has been canceled.
///
/// Typically, the consumer creates a [CancellationTokenSource] and then passes
/// the [token] to another operation. The consumer can then call [cancel],
/// while the operation can only check if it has been canceled.
///
/// FUTURE: If we want a stream to listen for when a cancellation has happened,
/// use CancelableCompleter from the async package instead.
@patkujawa-wf
patkujawa-wf / pubupgrade.py
Last active July 28, 2021 20:52
pubupgrade: Combine your dart pubspec files' information so that you can easily upgrade your pubspec.yaml to the versions in your pubspec.lock
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import print_function
import argparse
import sys
import re
import yaml # PyYAML
@patkujawa-wf
patkujawa-wf / PULL_REQUEST_TEMPLATE.md
Last active February 18, 2017 02:56
Markdown checkboxes that don't persist in github when checked in the rendered view

Problem

Solution

Areas of Impact

Test Overview (+10 Instructions)

@patkujawa-wf
patkujawa-wf / sed1line.bash
Created July 11, 2016 15:23
USEFUL ONE-LINE SCRIPTS FOR SED (Unix stream editor), sed1line.txt
-------------------------------------------------------------------------
USEFUL ONE-LINE SCRIPTS FOR SED (Unix stream editor) Dec. 29, 2005
Compiled by Eric Pement - pemente[at]northpark[dot]edu version 5.5
Latest version of this file (in English) is usually at:
http://sed.sourceforge.net/sed1line.txt
http://www.pement.org/sed/sed1line.txt
This file will also available in other languages:
Chinese - http://sed.sourceforge.net/sed1line_zh-CN.html
@patkujawa-wf
patkujawa-wf / dump.py
Last active July 12, 2018 17:23
all-purpose function for dumping any python thing in a mostly-readable manner (aka dump)
import logging
# MAGIC-NUMBER: max length is just some guess at a reasonable size, e.g. 80 cols by 500 lines
def dump(value, msg='DUMP', max_length=80 * 500, stdout=False, pick=(), skip=(),
loglevel=logging.DEBUG):
"""
Write as verbose of a description of the value as possible to logging.DEBUG.
See http://stackoverflow.com/q/27830888/116891
@patkujawa-wf
patkujawa-wf / test_multiple_files_same_asserts_using_meta_programming.py
Last active August 29, 2015 14:17
Gold/approved file testing all methods in a test class against every file in a directory via metaclass metaprogramming in Python
import glob
import inspect
import os
import re
import unittest
# http://superuser.com/a/748264/43406. NOTE ^ in front for negation
_unsafe_filename_regex = re.compile('([^\[\]\.0-9a-zA-Z-,;_])')
@patkujawa-wf
patkujawa-wf / pretty_json.sh
Created January 2, 2015 18:51
Pretty print a json file with python via the command line
# From https://betamax.readthedocs.org/en/latest/cassettes.html
python -m json.tool cassette.json
@patkujawa-wf
patkujawa-wf / caching_example.py
Created December 30, 2014 19:14
Automatic caching with google app engine ndb example
# Taken from http://ae-book.appspot.com/static/pgae-ndb-20121009.pdf
# Video at https://www.youtube.com/watch?v=xZsxWn58pS0#t=3383
## Automatic Caching
# • Two automatic caching features
# • “In-context” cache
# • Memcache storage
# • Same basic idea, difference in scope
# • Context cache starts empty for each request
# • Minimizes datastore interactions throughout the request handler code
@patkujawa-wf
patkujawa-wf / cursors_example.py
Created December 30, 2014 19:08
Cursors in google app engine example, pagination with urlsafe conversion
# Taken from http://ae-book.appspot.com/static/pgae-ndb-20121009.pdf
# Video at https://www.youtube.com/watch?v=xZsxWn58pS0#t=3184
## Cursors
# • Fetch results using an iterator, with cursors enabled:
it = query.iter(produce_cursors=True)
for result in it: # ...
# • Test whether there’s another result:
if it.has_next(): # ...
if it.probably_has_next(): # ...
@patkujawa-wf
patkujawa-wf / projection_query_example.py
Created December 30, 2014 19:04
Projection query example in google app engine
# Taken from http://ae-book.appspot.com/static/pgae-ndb-20121009.pdf
# Video at https://www.youtube.com/watch?v=xZsxWn58pS0#t=2970
query = Player.query()
results = query.fetch(20,
projection=[Player.name, Player.level])
for player in results:
# player.name ...
# (player.score not set)
# Projected property values are pulled directly from