Skip to content

Instantly share code, notes, and snippets.

View afparsons's full-sized avatar
🏠
Working from home

Andrew Parsons afparsons

🏠
Working from home
  • Boston, Massachusetts
  • 10:36 (UTC -04:00)
View GitHub Profile
@mikybars
mikybars / validate_dataclass.py
Last active May 24, 2023 19:11
Generic solution for `@dataclass` validation in Python with custom setters
from dataclasses import dataclass
class Validations:
def __setattr__(self, prop, val):
if (validator := getattr(self, f"validate_{prop}", None)):
object.__setattr__(self, prop, validator(val) or val)
else:
super().__setattr__(prop, val)
@alvarocavalcanti
alvarocavalcanti / Dockerfile.dev
Last active June 13, 2024 00:51
Configuring Python Remote Interpreter using Docker
FROM python:3.7
ENV PYTHONUNBUFFERED 1
WORKDIR /code
# Copying the requirements, this is needed because at this point the volume isn't mounted yet
COPY requirements.txt /code/
# Installing requirements, if you don't use this, you should.
# More info: https://pip.pypa.io/en/stable/user_guide/
# https://hakibenita.com/fast-load-data-python-postgresql
from typing import Iterator, Dict, Any, Optional
from urllib.parse import urlencode
import datetime
#------------------------ Profile
import time
@mlissner
mlissner / filters.js
Created March 7, 2019 23:09
Regular expressions for parsing law citations from the U.S., Canada, Europe, and Australia (and probably more). Originally from the Jureeka project.
// ==UserScript==
// @name Jureeka
// @namespace http://www.jureeka.org
// @description Turns legal citations in webpages into hyperlinks that direct you to online legal source material.
// ==/UserScript==
// $Id: jureeka.js 1256 2012-02-13 19:06:16Z imad $
/*
Warnings:
@dbtek
dbtek / venv_wrapper
Last active June 23, 2024 13:56
Python 3 venv wrapper. Manages all virtual environments under ~/.venv/ .
# venv_wrapper, manage all virtual environments under ~/.venv/
# Include following in .bashrc / .bash_profile / .zshrc
# See https://gist.github.com/dbtek/fb2ddccb18f0cf63a654ea2cc94c8f19
# Usage
# $ mkvenv myvirtualenv # creates venv under ~/.venv/
# $ venv myvirtualenv # activates venv
# $ deactivate # deactivates venv
# $ rmvenv myvirtualenv # removes venv
export VENV_HOME="$HOME/.venv"
@gbaman
gbaman / graphql_example.py
Created November 1, 2017 00:18
An example on using the Github GraphQL API with Python 3
# An example to get the remaining rate limit using the Github GraphQL API.
import requests
headers = {"Authorization": "Bearer YOUR API KEY"}
def run_query(query): # A simple function to use requests.post to make the API call. Note the json= section.
request = requests.post('https://api.github.com/graphql', json={'query': query}, headers=headers)
if request.status_code == 200:
import nltk
from nltk.tokenize.treebank import TreebankWordTokenizer
class TreebankSpanTokenizer(TreebankWordTokenizer):
def __init__(self):
self._word_tokenizer = TreebankWordTokenizer()
def span_tokenize(self, text):
@codingjoe
codingjoe / django_docs.md
Last active July 24, 2022 23:16
Build Django docs like a pro!

Build Django docs like a pro!

Sphinx config

docs/conf.py

import importlib
import inspect
import os
import sys
@daattali
daattali / linkedin.R
Created March 5, 2016 11:11
Scraping Twitter and LinkedIn info in R
# Get a person's name, location, summary, # of connections, and skills & endorsements from LinkedIn
# URL of the LinkedIn page
user_url <- "https://www.linkedin.com/in/daattali"
# since the information isn't available without being logged in, the web
# scraper needs to log in. Provide your LinkedIn user/pw here (this isn't stored
# anywhere as you can see, it's just used to log in during the scrape session)
username <- "yourusername"
password <- "yourpassword"
@PurpleBooth
PurpleBooth / README-Template.md
Last active June 30, 2024 00:35
A template to make good README.md

Project Title

One Paragraph of project description goes here

Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.

Prerequisites