Skip to content

Instantly share code, notes, and snippets.

View benkehoe's full-sized avatar

Ben Kehoe benkehoe

View GitHub Profile
<!DOCTYPE html>
<html>
<head>
<title>Draw Polygon</title>
<script type="text/javascript" src="http://lib.ivank.net/ivank.js"></script>
<script type="text/javascript" src="http://polyk.ivank.net/polyk.js"></script>
<script type="text/javascript">
var stage, s, dragged, complete, stopClick, rmv, cent, jsonText, cvs, sbt, area, centX, centY;
var remove = false;
//dragged is set to true if a Dot is being dragged
@benkehoe
benkehoe / benktools.sty
Last active August 29, 2015 14:06
LaTeX package of handy macros
\ProvidesPackage{benktools}
% Usage:
% \usepackage{benktools}
% \benkhide <-- put this when you want to remove all
% the todos, notes, version info, etc.
% e.g., for the final version
% updates at https://gist.github.com/benkehoe/c46647134d4bbd514869
@benkehoe
benkehoe / JSON <-->YAML coversion scripts.md
Last active August 26, 2020 15:25
JSON <--> YAML conversion scripts

JSON <--> YAML conversion scripts

JSON is very standard. YAML, a superset of JSON, is very readable. Got something that needs JSON, and want to write the input in YAML? Use yaml2json. Have JSON and want to view it in a more readable format? Use json2yaml.

Use with files or stdin/stdout. Pretty-print the JSON if you want.

Requires pyyaml (via pip or easy_install), aka the python-yaml Ubuntu package.

A version of these files is available at tinyurl/json2yaml and tinyurl.com/yaml2json for you to wget or curl -L

@benkehoe
benkehoe / getch.py
Last active May 22, 2018 07:57
Python stdin char getter
"""
Copyright 2018 Ben Kehoe
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTH
@benkehoe
benkehoe / awssh
Last active January 31, 2017 21:59
AWS EC2 ssh shell functions
# Shell functions for ssh-ing into and
# Features automatic adding of the key file when it is specified in
# AWSSH_KEY. If no user is given in the hostname, it will use the value
# in AWSSH_DEFAULT_USER, or ec2-user if that is not set.
# Sets StrictHostKeyChecking off, so it doesn't ask you if you want to
# connect. Doesn't add the IP to known_hosts, though it will warn you
# every time that it has.
awssh ()
(

Use case: hit counter

At every path, just returns the number of times that path has been requested. Each stage should get its own table to store the counters, rather than sharing a table. Ideally, the linking between the table and the Lambda function happens at deployment time (i.e., the stages share the same code object in S3, not each having separate but identical objects) and not at build time (with separate, different code objects) or run time (that requires making extra API calls inside the Lambda function).

The crux of it is the following:

@benkehoe
benkehoe / LambdaBase.py
Last active October 23, 2023 20:30
Code pattern for implementing class-based AWS Lambda handlers in Python
"""Base class for implementing Lambda handlers as classes.
Used across multiple Lambda functions (included in each zip file).
Add additional features here common to all your Lambdas, like logging."""
class LambdaBase(object):
@classmethod
def get_handler(cls, *args, **kwargs):
def handler(event, context):
return cls(*args, **kwargs).handle(event, context)
return handler
@benkehoe
benkehoe / argparse_repl.py
Last active March 21, 2019 04:32
Simple pattern for adding a REPL to argparse-based command line programs
# This came up when I couldn't add dependencies beyond the stdlib for a certain script
import argparse
import sys, os.path
def run(args):
# Do actual things
pass
def main():
@benkehoe
benkehoe / aws.opml
Last active November 20, 2023 20:32
AWS RSS feeds
<?xml version="1.0" encoding="UTF-8"?>
<opml version="1.0">
<head>
<title>AWS RSS feeds 2019-04-22</title>
</head>
<body>
<outline text="AWS" title="AWS">
<outline type="rss" text="Infrastructure &amp; Automation" title="Infrastructure &amp; Automation" xmlUrl="https://aws.amazon.com/blogs/infrastructure-and-automation/feed/" htmlUrl="https://aws.amazon.com/blogs/infrastructure-and-automation/"/>
<outline type="rss" text="AWS Developer Blog" title="AWS Developer Blog" xmlUrl="http://feeds.feedburner.com/AwsDeveloperBlog" htmlUrl="https://aws.amazon.com/blogs/developer/"/>
@benkehoe
benkehoe / aws_error_utils.py
Last active January 27, 2022 22:09
Error matching for botocore
# This is a now proper library (that can still be copied into your project as a single file)
# https://github.com/benkehoe/aws-error-utils
# MIT No Attribution
#
# Copyright 2022 Ben Kehoe
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of this
# software and associated documentation files (the "Software"), to deal in the Software
# without restriction, including without limitation the rights to use, copy, modify,