Skip to content

Instantly share code, notes, and snippets.

Being foxy

Andy Ingram AndrewIngram

Being foxy
View GitHub Profile
AndrewIngram /
Last active May 28, 2021
Filter Count Mixin for Django's admin
from django.contrib import admin
from django.db.models import Count, F
class FilterCountMixin(admin.SimpleListFilter):
def __init__(self, request, params, model, model_admin):
# Store the request so we can reapply all the filters properly later
self.request = request
super().__init__(request, params, model, model_admin)
def get_filter_counts_parameter_name(self):
AndrewIngram /
Last active Dec 12, 2020
Django one-off on_save callbacks
from django.db import transaction
from django.db import models
from django.db.models.signals import post_save
def on_save(obj: models.Model, callback, on_commit=False):
Attaches a one-off callback that's triggered after a Django model instance is
saved. Optionally makes use of transaction.on_commit to defer until any wrapping
transaction has also committed.
AndrewIngram / PostDetail.jsx
Last active May 9, 2021
Updated Next.js with Relay (still using getInitialProps)
View PostDetail.jsx
import React from "react";
import { graphql } from "react-relay";
import createPageContainer from "../relay/createPageContainer";
import PostLayout from "../components/PostLayout";
import Header from "../components/Header";
import Shell from "../layouts/Shell";
AndrewIngram / schema.graphql
Last active Jan 7, 2021
Derived Dribbble Scema
View schema.graphql
# Not everything is defined here, just what was mentioned in the article
type User {
id: ID!
name: String!
avatar: Image!
isPro: Boolean!
viewerHasFollowed: Boolean!
shots(exclude: ID): ShotConnection!
AndrewIngram /
Last active Apr 13, 2021
Proper cursors with Graphene + Django. Graphene-Django's stock connections use limit/offset logic under the hood, making the whole cursor-based connection modelling kinda pointless.
import datetime
import operator
from base64 import b64decode as _unbase64
from base64 import b64encode as _base64
from functools import reduce
from django.db.models import Q
from graphene import relay
from graphql_relay.connection import connectiontypes
AndrewIngram / Homepage.tsx
Created Dec 31, 2019
Next.js serverless dynamic routing with centralised routes
View Homepage.tsx
// src/pages/Homepage.tsx
import React from "react";
export default function Homepage() {
return <div>Homepage/div>;
View SketchSystems.spec
My Awesome Sketch
First State
some event -> Second State
Second State
View LoginForm.js
import React from "react";
import useLogin from "@zego/hooks/useLogin";
import BaseLoginForm from "./BaseLoginForm";
import { withTrackableFeature } from "@zego/tracking";
const LoginFormImpl = props => {
const login = useLogin();
AndrewIngram / routes.js
Created Jan 10, 2019
Basic router on top of Next.js
View routes.js
import { include, createRouter } from "./lib/router";
const commonRoutes = [
path: "/terms-of-business/",
name: "terms-of-business",
page: "TermsOfBusinessPage",
AndrewIngram / routes.js
Last active Jan 9, 2019
Router API Idea
View routes.js
import { routes, include } from "@framework/router";
import { relayView, xmlView } from "@framework/engine";
const gbRoutes = routes(
route({ path: "/", view: "./views/gb/HomepageGb" }),
route({ path: "/scooter/", view: "./views/gb/ScooterGb" }),
route({ path: "/car/", view: "./views/gb/CarGb" }),
route({ path: "/private-hire/", view: "./views/gb/PrivateHireGb" }),
route({ path: "/blog/:slug/", view: "./views/BlogPost" })