Skip to content

Instantly share code, notes, and snippets.

"""explore pylint W0640"""
#
# A test of how a lambda used to filter a list works
# when the filter criteria var is defined in a loop.
#
# This was written because pylint was giving me
# warning W0640: cell-var-from-loop
# for a use of filter materially similar to the (greatly simplified)
# example below, and I wanted to know if it was actually something
# to be concerned about.
@jrheling
jrheling / groupby_equiv.py
Created January 29, 2020 12:56
python groupby() equivalent with unsorted immutable input
# goal: use nested list comprehension to do the equivalent of groupby
# but with unsorted input that can't be changed
#
# given input like:
# [('foo', 1), ('bar', 3), ('foo', 4), ('bar', 2)]
#
# produce output like:
# [[('foo', 1), ('foo', 4)], [('bar', 3), ('bar', 2)]]
#
# groupby() can do this, but needs its input sorted. Here's how to do
@jrheling
jrheling / typeguard_in_inner_function2.ts
Created December 18, 2019 17:47
typescript type guards around closure definitions are ignored by the inner function
// Typescript handles type guards fundamentally differently than it
// handles data in the context of a closure.
//
// This is not new, and was documented at
// https://github.com/microsoft/TypeScript/issues/7662
// and
// https://github.com/microsoft/TypeScript/issues/8552
//
// Demonstration follows.
@jrheling
jrheling / typeguard_in_inner_function.ts
Last active December 17, 2019 17:05
code demonstrating that TS type guards defined in the lexical scope of a closure's inner function aren't understood inside the inner function
interface namedThing {
name: string;
val: number;
}
interface myType {
p1: namedThing | null;
p2: number;
}
@jrheling
jrheling / yourapp
Created June 12, 2018 14:54 — forked from leplatrem/yourapp
gunicorn virtualenv init.d script (could be simpler with upstart)
#! /bin/bash
### BEGIN INIT INFO
# Provides: YOURAPP
# Required-Start: nginx
# Required-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: The main gunicorn process for YOURAPP
# Description: The gunicorn process that receives HTTP requests
# from nginx and proxies them to YOURAPP.
@jrheling
jrheling / dash-react.py
Last active January 1, 2016 18:33 — forked from eob/dash-listen-2.py
Simple script to watch for and react to Amazon Dash button pushes.
#!/usr/bin/python
# based on https://medium.com/@edwardbenson/how-i-hacked-amazon-s-5-wifi-button-to-track-baby-data-794214b0bdd8
#
# This is a quick hack. As such, it:
# * lacks exception handling
# * has no pretense of object orientation
# * needs root privs (for network monitoring) but doesn't do anything
# to make that safe (e.g. drop privs, etc.)
# * gets configured manually (see below)