Skip to content

Instantly share code, notes, and snippets.

View toolness's full-sized avatar

Atul Varma toolness

View GitHub Profile
@toolness
toolness / nycdb-notes.md
Last active January 2, 2019 12:51
NYC-DB Notes
@toolness
toolness / typescript-wtf.md
Last active July 11, 2022 14:50
Extremely ridiculously confusing things about TypeScript

By and large, TypeScript is an incredible tool that I'm very grateful for, but sometimes it really makes me want to tear my hair out.

Narrowing functions WTF

TypeScript 3.1 introduced a breaking change involving narrowing functions that I have no idea how to work around.

Here's one attempt to make an unconstrained generic into something that's vaguely constrained: I want to define a type T in which we don't know what properties it has, but we want to make sure that any properties it does have are booleans.

type ObjWithBooleanValues = {
@toolness
toolness / annoqueries.py
Last active August 11, 2018 23:13
Simple Graphene wrapper that uses type annotations to generate GraphQL schemas.
import inspect
from typing import Type, Any, Callable
import graphene
from graphql import ResolveInfo
class AnnoQuery:
'''
Base class for defining a GraphQL query schema and resolvers that relies
on type annotations rather than more verbose (and un-type-checkable)
Graphene definitions.
@toolness
toolness / docassemble-docker-compose.yml
Created July 19, 2018 21:51
Docker compose configuration for docassemble.
version: '3'
services:
app:
image: jhpyle/docassemble
# https://docassemble.org/docs/docker.html#tocAnchor-1-10-3
volumes:
- ./backup:/usr/share/docassemble/backup
ports:
- 80:80
stop_grace_period: 1m
@toolness
toolness / Dockerfile
Last active May 1, 2018 21:48
Super simple scaffolding for building a Django app using Docker.
FROM python:3.6
COPY requirements.txt .
RUN pip install -r requirements.txt
@toolness
toolness / usa-class-usage.md
Last active August 17, 2017 14:09
USWDS CSS class usage

The following output was generated by the find-usa-class-usage.js script in 18F/uswds-crawler.

Class Usage
usa-grid 75%
usa-width-one-half 54%
usa-button 51%
usa-unstyled-list 45%
usa-width-one-third 45%
usa-footer 42%
@toolness
toolness / fix-18f-coc.sh
Created June 14, 2017 12:43
Script to fix broken Code of Conduct links in 18F projects
#! /bin/bash
set -e
sed -ri 's/github\.com\/18F\/code-of-conduct\/blob\/master\/code-of-conduct\.md/18f\.gsa\.gov\/code-of-conduct\//' CONTRIBUTING.md
git checkout -b coc-fix
git add CONTRIBUTING.md
@toolness
toolness / migrate_to_hugo.py
Last active May 14, 2017 12:10
A hacky script to migrate my 2014 Wordpress content to Hugo.
# coding=utf-8
'''
I wrote this hacky script to migrate my Wordpress content from 2014
to Hugo posts. It requires:
* Python 2.7.
* A trivial Django 1.8 project with the 'the-real-django-wordpress'
app/package installed (it's on PyPI). It's assumed that the project
@toolness
toolness / atmega328p-fuse-notes.md
Created March 27, 2017 01:48
Fuse notes for the ATMega328p

I purchased three Amtel ATMega328p MCUs from Amazon. The product was advertised as coming "w/ Arduino UNO Bootloader", which I thought nothing of because I was going to overwrite the bootloader with my own programs.

However, I did not anticipate the fact that these units would actually come with their fuses set to the Arduino UNO defaults: most notably, they configured the unit to be driven by an external clock, which disabled the chip's internal 1 Mhz oscillator. This made it impossible to communicate with the chip via avrdude, as the chip was eternally waiting for an external clock to drive it.

Fortunately, after much searching and experimentation, I found a modified ArduinoISP script by a david.prentice that modified the default ArduinoISP to emit a slow clock signal on the Arduino's digital pin #3. Once I connected this to my MCU's XTAL1 clock input, `avrdu

@toolness
toolness / sshify.py
Created March 14, 2017 20:31
A script to run a command within an ssh-agent session.
#! /usr/bin/env python3
"""
This utility will execute the given command (by default, your shell)
in a subshell, with an ssh-agent process running and your
private key added to it. When the subshell exits, the ssh-agent
process is killed.
"""
# This code was written by Atul Varma in February 2017. It requires