Skip to content

Instantly share code, notes, and snippets.

View jefftriplett's full-sized avatar
Living the dream

Jeff Triplett jefftriplett

Living the dream
View GitHub Profile
@mattharrison
mattharrison / Idiomatic Pandas.ipynb
Last active July 8, 2024 06:21
Idiomatic Pandas: 5 tips for better pandas code
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@davemerwin
davemerwin / DJANGO-HTMX Class Based View Request Grab to Change Templates
Last active June 15, 2024 18:07
An example of a Class Based View using django-htmx to determine what template to return
class AddImage(LoginRequiredMixin, CreateView):
"""
adds a image
"""
form_class = ImageForm
model = Image
def get_template_names(self):
if self.request.htmx:
@FlipperPA
FlipperPA / country_codes.py
Last active July 17, 2021 23:43
Countries Listed by the International Dialing Country Code, as a Python Dict.
country_dialing_codes_by_code = {
1: ["Canada", "Caribbean Nations", "USA"],
7: ["Kazakhstan", "Russia", "Tajikistan", "Uzbekistan"],
20: ["Egypt"],
27: ["South Africa"],
30: ["Greece"],
31: ["Netherlands"],
32: ["Belgium"],
33: ["France", "Monaco"],
34: ["Spain"],
@0xabad1dea
0xabad1dea / copilot-risk-assessment.md
Last active September 11, 2023 10:21
Risk Assessment of GitHub Copilot

Risk Assessment of GitHub Copilot

0xabad1dea, July 2021

this is a rough draft and may be updated with more examples

GitHub was kind enough to grant me swift access to the Copilot test phase despite me @'ing them several hundred times about ICE. I would like to examine it not in terms of productivity, but security. How risky is it to allow an AI to write some or all of your code?

Ultimately, a human being must take responsibility for every line of code that is committed. AI should not be used for "responsibility washing." However, Copilot is a tool, and workers need their tools to be reliable. A carpenter doesn't have to

@sethmlarson
sethmlarson / warning-stacklevel.py
Last active February 11, 2022 14:20
Dynamically determine stacklevel for use with warnings.warn(..., stacklevel=X)
import inspect
import sys
from pathlib import Path
def warn_stacklevel() -> int:
"""Dynamically determine stacklevel for warnings based on the call stack"""
try:
# Grab the root module from the current module '__name__'
module_name = __name__.partition(".")[0]
@bmispelon
bmispelon / update.py
Created March 2, 2021 09:53
[Django ORM] Updating a JSONField based on the value of another field
"""
How to update JSONField based on the value of another field.
For example:
class MyModel(models.Model):
name = models.CharField(...)
data = models.JSONField()
How to update the MyModel table to store the `name` field inside the `data`
@niccolomineo
niccolomineo / filters.py
Last active August 27, 2024 11:53
Django ArrayField inheritable list filter
"""Django filters."""
from django.contrib.admin import SimpleListFilter
class ArrayFieldListFilter(SimpleListFilter):
"""An admin list filter for ArrayFields."""
def lookups(self, request, model_admin):
"""Return the lookups."""
@austinhyde
austinhyde / README.md
Last active September 5, 2022 03:23
Run Script, with dev docker image

One of the biggest barriers to starting in an unfamiliar repo is understanding how to start up the development environment, build the code, and other common tasks. Once a developer is established in a codebase, it's important to minimize development friction with common tasks.

The run script here is a very minimal script that makes it easy to see how to get started, what common tasks are available, and automates those tasks, no matter how trivial. Importantly for long-term maintainability, it allows the "repo maintainers" to change details about, say, starting a dev database, without most other engineers needing to care how that gets done (maybe we use docker-compose, maybe we use raw docker, maybe vagrant). And if they do care, they can just read the script or watch its output.

Importantly, the script is just plain old bash. Most developers are probably familiar with the syntax, and it's ubiquitous, meaning there's no dependencies to install and no esoteric shell-like syntaxes (like make) or librarie

@kingbuzzman
kingbuzzman / add_on_delete_cascade.py
Created January 19, 2021 11:08
libcst django 1.11 to 2.x add on_delete=models.CASCADE if missing with formatting
# pip install libcst
python -c "$(cat <<EOF -
import libcst as cst
import os
import difflib
def build_arg(inline):
return cst.Arg(
@djm
djm / workflow.yml
Created January 9, 2021 18:28
Problem: pulling docker images with dynamically generated tags, using just the GitHub Action yaml syntax
name: Build Docker image & run dependent jobs that pull tagged image
# Desires:
#
# 1) First job builds, pushes and tags docker image with ref/pr-number/sha - something specific to that branch.
# 2) n-jobs after this depend on success of first job, and will pull an image based on tag used in first job.
# 3) The n-jobs mount host GA workspace, or checkout code within the container itself. Not bothered which.
# 4) Rely on GitHub Action's yaml docker constructs only, rather than calling docker @ the cli
# This is not a _true_ requirement! I know how to get around it, but it is what I originally
# set out hoping to do - because it works very nicely when you're dealing with static tags