Skip to content

Instantly share code, notes, and snippets.

@dwinston
dwinston / lisp_parser.py
Created July 8, 2019 21:47
Code that takes some Lisp code and returns an abstract syntax tree (AST). The AST represents the structure of the code and the meaning of each token.
"""
Code that takes some Lisp code and returns an abstract syntax tree (AST).
My lisp knows about the following types of tokens:
- the expression delimiters `(` and `)`
- strings (delimited by quote characters)
- numbers
- boolean values `true` (corresponding to Python's `True`) and `false` (corresponding to Python's `False`)
- the null value `null` (corresponding to Python's `None`)
@dwinston
dwinston / mprester_bulk_query.py
Last active July 16, 2020 13:58
bulk query of Materials Project data via pymatgen MPRester, and saving to local MongoDB
from pymatgen import MPRester
try:
from pydash import chunk as get_chunks
except ImportError:
from math import ceil
def get_chunks(array, size=1):
chunks = int(ceil(len(array) / float(size)))
return [array[i * size:(i + 1) * size]
for i in range(chunks)]
@dwinston
dwinston / csv-to-vcard.py
Created January 19, 2018 00:41
Convert a CSV file of people to vCard files for updating iOS contacts
"""
Convert a CSV file of the form
```
name, email, cell
First Last, bob@example.com, 800-555-1234
...
```
to vCard (vcf) files suitable for creating/updating iOS contacts.
Based on https://codereview.stackexchange.com/questions/3517/converting-a-csv-to-vcards-in-python
@dwinston
dwinston / dns_check_email_domain.py
Created January 11, 2018 22:47
Use dnspython library to validate an email domain via DNS MX, AAAA, and A records. A sanity check that avoids abusing the email server.
import re
import dns.resolver
def dns_check_email_domain(domain):
"""
Query DNS records to verify that email server is possible on domain.
If no DNS records are found, user should confirm email address.
"""
response = {}

Keybase proof

I hereby claim:

  • I am dwinston on github.
  • I am dwinston (https://keybase.io/dwinston) on keybase.
  • I have a public key ASDlWFACdSLc3gOp8yLr1jda7bFkjDYmEGY8MhBypnNiXgo

To claim this, I am signing this object:

@dwinston
dwinston / nwordspass.py
Created April 3, 2017 22:23
Generate a password/passphrase that is just many words strung together
"""Generate n-word (default n=5) passwords separated by sep (default '-').
Uses your friendly neighborhood words file by default.
Simple Use: `python nwordspass.py`
Help: `python nwordspass.py --help`
"""
import argparse
import random
@dwinston
dwinston / citrination_play.py
Created November 22, 2016 19:06
Get experimental Si band gaps from Citrination API
from citrination_client import *
client = CitrinationClient('API_KEY', 'https://citrination.com')
query = PifQuery(
from_index=0,
size=1000,
system=SystemQuery(
chemical_formula=ChemicalFieldOperation(
filter=ChemicalFilter(equal="Si")
@dwinston
dwinston / regonline_suds_example.py
Created April 26, 2016 21:58
Example use of RegOnline SOAP service using Python suds library
"""
Logs in to get an API token and then uses it to retrieve
the number of confirmed registrations for an event.
"""
from suds.client import Client
USERNAME = ''
PASSWORD = ''
EVENTID = 1
@dwinston
dwinston / mpcomplete_submit_structures_example.ipynb
Last active May 12, 2016 00:34
Example of Bulk Submission of Crystal Structures (CIF files) to the Materials Project (MPComplete)
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.