This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
This snippet will return all the letting agents, bucketed into discrete bands based on distance from | |
an origin point (for example, the user's current location), then sorted alphabetically within each | |
band. The goal being to prioritise agents in close proximity, but not excessively 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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { mergeWith } from "lodash"; | |
export function nullPrototypeFix(object: Object): Object { | |
return mergeWith({}, object, (a: any, b: any) => { | |
if (b === null || typeof b === "undefined") { | |
return b; | |
} else if (typeof b.toJSON == "function") { | |
return b.toJSON(); | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getIsLiked(viewerId, entityId) { | |
// hit a database or something | |
} | |
function toggleLikeStatus(viewerId, entityId) { | |
// hit a database or something | |
return !currentStatus; | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def my_fun(user_or_id: UserOrId): | |
user = get_user(user_or_id) | |
# Do something with user | |
# These both do the same thing (but the first avoids the extra db hit) | |
my_fun(user) | |
my_fun(user.id) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { json } from "next-runtime"; | |
import jwt from "jsonwebtoken"; | |
const SESSION_KEY = "some-secret"; | |
export function readSession(cookies) { | |
const sessionCookie = cookies.get("session"); | |
let data = {}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Given an input and a mask, will return just part we care about | |
* | |
* e.g. | |
* input: 0b11101111 | |
* mask: 0b00110000 | |
* returns: 0b10 | |
*/ | |
function maskedValue(input: number, mask: number): number { | |
return (input & mask) >> Math.log2(mask & -mask); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { v5 as uuidv5, NIL } from 'uuid'; | |
function stableUuid(namespace, name) { | |
return uuidv5(name, uuidv5(namespace, NIL)) | |
} | |
// > stableUuid('Some namespace', 'some name') | |
// '019761ac-2321-5ae0-9086-70c9557bcc58' | |
// > stableUuid('Some namespace', 'some name') | |
// '019761ac-2321-5ae0-9086-70c9557bcc58' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import formidable from "formidable"; | |
export default function formData(request) { | |
const form = formidable({ multiples: true }); | |
return new Promise((resolve, reject) => { | |
form.parse(request, (err, fields, files) => { | |
if (err) { | |
reject(err); | |
return; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.container { | |
background-color: hsl(346deg, 83%, 51%); | |
background-image: linear-gradient( | |
45deg, | |
hsla(240deg, 100%, 20%, 1) 0%, | |
hsla(240deg, 100%, 20%, 0) 50% | |
), | |
linear-gradient( | |
45deg, | |
hsla(55deg, 100%, 50%, 0) 50%, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import logging | |
from django.db import models, transaction | |
from django.db.models.signals import post_save | |
logger = logging.getLogger(__name__) | |
def on_save(obj: models.Model, callback): | |
""" | |
Attaches a one-off callback that's triggered after a Django model instance is |