Skip to content

Instantly share code, notes, and snippets.

View adamghill's full-sized avatar

Adam Hill adamghill

View GitHub Profile
@adamghill
adamghill / justfile
Created July 6, 2024 20:20
Example justfile for Python projects
# https://just.systems
set quiet
set dotenv-load
set export
# List commands
_default:
just --list --unsorted --justfile {{justfile()}} --list-heading $'Available commands:\n'
@adamghill
adamghill / docker.md
Created May 25, 2024 17:44
Useful docker CLI commands that I always forget

Note: IMAGE_NAME should be replaced with some unique name.

  • Build the Dockerfile in the current directory: docker build -t IMAGE_NAME .
  • Get the size of the resulting Docker image: docker image save IMAGE_NAME | wc -c | numfmt --to=si
  • Run the resulting Docker image for web apps: docker run -p 127.0.0.1:80:3000 IMAGE_NAME
  • Open a shell in a Docker image: docker run -it --rm IMAGE_NAME /bin/bash
@adamghill
adamghill / Dockerfile
Last active June 1, 2024 03:30
Multi-stage Dockerfile with Python and `uv`
# Layer with Python and some shared environment variables
FROM python:3.10-slim-bullseye as python
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1
# Layer for installing Python dependencies
FROM python as dependencies
ENV PIP_DISABLE_PIP_VERSION_CHECK=1
// This was an initial prototype, but https://github.com/adamghill/conjure has the latest version
@adamghill
adamghill / helpers.py
Created December 2, 2023 20:51
Helper method to verify two dictionaries are the same with helpful error messages
from typing import Union
def assert_dictionaries(dictionary_one: Union[dict, list], dictionary_two: dict) -> None:
"""Helper method to verify two dictionaries are the same. Display helpful error messages
when the two dictionaries are different.
Args:
dictionary_one: The first dictionary.
dictionary_two: The second dictionary.
@adamghill
adamghill / timeit.py
Created November 10, 2023 17:34
timeit decorator
from contextlib import contextmanager
import time
@contextmanager
def timeit():
"""
Decorator that prints out how long a function took to run.
"""
now = time.monotonic()
@adamghill
adamghill / dork.js
Last active April 6, 2024 15:06
The most important JavaScript framework ever created. https://github.com/adamghill/dorkjs
/*
Moved to https://github.com/adamghill/dorkjs.
*/
@adamghill
adamghill / stargazers.gql
Last active November 16, 2023 00:05
Get last stargazers for repos
# Query GitHub for all new stargazers for a particular user's repositories
query($login: String!) {
user(login: $login) {
login
repositories(last: 5, orderBy: {field: STARGAZERS, direction: ASC}) {
edges {
node {
name
url
@adamghill
adamghill / deploy-to-caprover.yml
Last active November 26, 2023 19:36
GitHub Action to build and deploy Docker image to CapRover
# Might be outdated! Check https://github.com/marketplace/actions/build-docker-and-deploy-to-caprover for the latest version.
name: Create and publish Docker image to CapRover
# Requires the following Action secrets to be set in your GitHub repo:
# - CAPROVER_APP_TOKEN
# - CAPROVER_SERVER_URL
on:
push:
@adamghill
adamghill / !steps.md
Created December 19, 2022 01:48
Steps to create a new Django project