Skip to content

Instantly share code, notes, and snippets.

View djm's full-sized avatar

Darian Moody djm

View GitHub Profile
@djm
djm / letting_agent.py
Created January 19, 2023 18:34 — forked from AndrewIngram/letting_agent.py
Django Queryset capabilites example
"""
This snippet will return all the letting agents, bucket into discrete bands based on distance from
an origin point (for example, the user's current location), then sorted alphabetically within each
bend. The goal being to prioritise agents in close proximity, but not execessively so -- all agents
within the same band should be given equal distance-related priority.
If there's a search term, we then boost the distance score based on the name's similiarity to the
search query.
"""
qs = LettingAgentLocation.objects.select_related("agent").filter(postcode__isnull=False)
@djm
djm / .envrc
Created September 20, 2022 23:17
YunoJuno Nix Developer Environment
export OP_ACCOUNT=yunojuno.1password.com
# Create .env.local if it does not exist
if [ ! -f .env.local ]
then
echo "Creating .env.local"
cat <<EOF > .env.local
# Place secret env variables from 1Password and custom overrides here
#
# Any variables here will override ones set in .env.native.dist
@djm
djm / migrate.py
Created July 4, 2022 17:38 — forked from bennylope/migrate.py
PostgreSQL migration script, Heroku -> Crunchy
#!/usr/bin/env python
import argparse
import os
import subprocess
import sys
import time
# Required so we don't generate tons of logs during restore
disable_logging_sql = "ALTER USER postgres RESET pgaudit.log;"
@djm
djm / gym.py
Created September 28, 2021 20:17 — forked from Alir3z4/gym.py
import os
import pickle
import warnings
import numpy as np
import pandas as pd
from sklearn.model_selection import train_test_split
from tensorflow.keras.callbacks import EarlyStopping
from tensorflow.keras.layers import Dense
from tensorflow.keras.layers import Dropout
@djm
djm / cuid.sql
Created June 3, 2021 15:17 — forked from srfrog/cuid.sql
CUIDs for PL/PgSQL
-- Collision-resistant ids optimized for horizontal scaling and performance, for PL/PgSQL.
-- Based on https://github.com/ericelliott/cuid
-- Version 1.0.0
-- Usage: SELECT cuid();
-- BEGIN CONFIG ---
-- Put a unique host ID (int) here per server instance.
-- Once set, this value should not be changed.
@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
@djm
djm / README.md
Last active March 16, 2023 04:02
Create a Chrome GitHub Repo Search Shortcut
@djm
djm / schema.md
Created January 4, 2021 23:12
nexus-plugin-prisma fix: property 'model'/'crud' does not exist on type ObjectDefinitionBlock

Just a quick fix dump for anyone not using ts-node-dev who is getting the Property 'model' does not exist on type ObjectDefinitionBlock or Property 'crud' does not exist on type ObjectDefinitionBlock: ensure your type generations are getting output where you think they are.

ts-node-dev does not transpile to a dist folder whereas other typescript watchers (like tsc-watch do). This is critical because if you output the generated types into your dist folder, VSCode and TypeScript won't find them, and you'll get the above error.

Also be aware that nexus & nexus-plugin-prisma have their own type generations and their own config definition for where to output each.

This is a commented example of makeSchema, with versions, so you can work out what's what:

nexus: v1.0.0 nexus-plugin-prisma: v0.27.0

@djm
djm / websocket_redis_pubsub.ts
Created January 2, 2021 12:32 — forked from philipyoungg/websocket_redis_pubsub.ts
Only support one room—but it's scalable horizontally
import * as redis from "redis";
import * as Websocket from "ws";
import { v4 } from "uuid";
import * as http from "http";
function noop() {}
enum WebsocketSendType {
BROADCAST_EMIT = "BROADCAST_EMIT",
}
@djm
djm / 1.tailwindUnderlineColor.js
Last active September 20, 2021 20:21
Underline Color Utilities Plugin for Tailwind (v1.2.0)
const plugin = require('tailwindcss/plugin')
/*
Creates colored underline utility classes.
Explanation: https://css-tricks.com/almanac/properties/t/text-decoration-color/
Browser Support: https://caniuse.com/#search=text-decoration-color
e.g