Skip to content

Instantly share code, notes, and snippets.

Avatar

Gustav Wengel GeeWee

View GitHub Profile
@GeeWee
GeeWee / test.cs
Created Jun 15, 2020
FluentAssertions ShouldBeEquivalentTo
View test.cs
using System.Collections.Generic;
using FluentAssertions;
using Xunit;
namespace AIP.FastlogFG.Test
{
public class FooTest
{
[Fact]
public void foo()
View autoprefetchmixin.py
class ChefViewSet(AutoPrefetchMixin, ModelViewSet):
serializer_class = ItalianChefSerializer
queryset = ItalianChef.objects.all()
View prefetcH_related.py
View n_plus_one.py
all_chefs = ItalianChef.objects.all()
for chef in all_chefs:
# Every time we reach the next line, we'll make an extra database call to fetch the
# favourite dish.
chefs_favourite_dish = chef.favourite_dish
print(f"{chef}'s favourite dish is {chefs_favourite_dish}")
View log-on-fail-reporter.js
/* eslint import/no-extraneous-dependencies: 0 */
const chalk = require('chalk');
const { getConsoleOutput } = require('jest-util');
const SummaryReporter = require('@jest/reporters/build/summary_reporter')
.default;
const DefaultReporter = require('@jest/reporters/build/default_reporter')
.default;
const getResultHeader = require('@jest/reporters/build/get_result_header')
.default;
View prefetching.py
import inspect
from collections import OrderedDict
from json import loads, dumps
from pprint import pprint
from typing import Type, Union
from django.core.exceptions import FieldError
from django.test import TestCase
from rest_framework.relations import RelatedField, ManyRelatedField
from rest_framework.serializers import ModelSerializer, Serializer, BaseSerializer, ListSerializer
View useConfirmDialog.tsx
interface ConfirmDialogConfig {
title: string;
text: string;
deleteButtonText: string;
}
/**
* A hook that will allow you to prompt a user for confirmation before doing a delete, by showing a "Are you sure" modal.
* @param action - the action to be performed when the user presses delete
View run-concurrently.py
def run_concurrently(times, args):
"""
Add this decorator to small pieces of code that you want to test
concurrently to make sure they don't raise exceptions when run at the
same time. E.g., some Django views that do a SELECT and then a subsequent
INSERT might fail when the INSERT assumes that the data has not changed
since the SELECT.
"""
def test_concurrently_decorator(test_func):
View transpiled-const-enum.js
if (someString === "APPLE" /* APPLE */) {
console.log("This is an apple!");
}
You can’t perform that action at this time.