Skip to content

Instantly share code, notes, and snippets.

Avatar

Atul Varma toolness

View GitHub Profile
@toolness
toolness / nycdb-analyze-hpd-corps-vs-head-officers.sql
Created Oct 29, 2020
NYCDB query to help compare HPD-registered corporation addresses vs. head officer addresses
View nycdb-analyze-hpd-corps-vs-head-officers.sql
CREATE FUNCTION pg_temp.address(hpd_contacts) RETURNS TEXT AS
$$
SELECT
CASE WHEN $1.businessstreetname IS NULL THEN
''::text
ELSE
COALESCE($1.businesshousenumber, '') || ' ' ||
$1.businessstreetname ||
CASE WHEN $1.businessapartment IS NULL THEN
''
@toolness
toolness / babel-cra-fun.js
Created Nov 19, 2019
Script to load a CRA app's babel config and run it w/ an additional example plugin.
View babel-cra-fun.js
//@ts-check
// This file can be dropped into the root of a project created
// via CRA w/ typescript support, e.g.:
//
// yarn create react-app cra-babel-fun --typescript
//
// It's just a proof-of-concept that shows how we can load
// the app's babel config and add a Babel plugin that executes
// before everything else.
@toolness
toolness / install_sdl2_rust_msvc.py
Last active May 12, 2019
Install SDL2 libraries so Rust+MSVC can find them.
View install_sdl2_rust_msvc.py
from pathlib import Path
from urllib.request import urlopen
from zipfile import ZipFile
from io import BytesIO
import os
import sys
assert 'win' in sys.platform, "We must be running on Windows."
MY_DIR = Path(__file__).parent.resolve()
@toolness
toolness / create_dataset.py
Created Apr 10, 2019
Create scaffolding for a new NYC-DB dataset.
View create_dataset.py
'''
This script makes it easy to create scaffolding for a new
NYC-DB dataset based on an input CSV file. Just copy it
into the `/src` directory of your NYC-DB repository,
open a terminal and run e.g.:
python create_dataset.py my_data.csv
This will create all the data files and Python code needed
for a new dataset called 'my_data' (or whatever you named
@toolness
toolness / Cargo.toml
Last active Feb 17, 2019
A simple "hello world" using Rust wasm-bindgen that doesn't require webpack.
View Cargo.toml
[package]
name = "wasm_hello"
version = "0.1.0"
authors = ["Atul Varma <varmaa@gmail.com>"]
edition = "2018"
[lib]
crate-type = ["cdylib"]
[dependencies]
@toolness
toolness / bzr-to-git.md
Last active Jan 19, 2019
Notes on converting a Bazaar repository to git
View bzr-to-git.md

I started with this Dockerfile:

FROM python:2.7

RUN pip install bzr

# Um, the following line might not actually do anything useful,
# possibly because we just installed bzr via pip instead of apt-get.
RUN apt-get update && apt-get --assume-yes install bzr-fastimport
@toolness
toolness / nycdb-schema.md
Last active Jan 31, 2019
NYC-DB schema
View nycdb-schema.md
View nycdb-notes.md
@toolness
toolness / typescript-wtf.md
Last active Oct 20, 2018
Extremely ridiculously confusing things about TypeScript
View typescript-wtf.md

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 Aug 11, 2018
Simple Graphene wrapper that uses type annotations to generate GraphQL schemas.
View annoqueries.py
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.