Skip to content

Instantly share code, notes, and snippets.

@jorisvddonk
jorisvddonk / ApolloComplexityPlugin.ts
Last active October 9, 2022 23:01
ApolloComplexityPlugin
import { ApolloServerPlugin, GraphQLServiceContext } from "apollo-server-plugin-base";
import { GraphQLSchema, separateOperations } from "graphql";
import { fieldConfigEstimator, getComplexity, simpleEstimator } from "graphql-query-complexity";
export class ApolloComplexityPlugin implements ApolloServerPlugin {
private schema: GraphQLSchema;
constructor(private maxComplexity: number) { }
public serverWillStart(service: GraphQLServiceContext) {
@wangzuo
wangzuo / mad.js
Created October 16, 2018 07:26
Minimum Absolute Difference
// Minimum Absolute Difference in an Array
// comparing each pair O(n^2)
// sort first O(nlogn) + O(n)
exports.mad = function(arr) {
const a = arr.sort((a, b) => a - b);
let min = -1;
for (let i = 0, l = a.length; i < l - 1; i++) {
const d = Math.abs(a[i] - a[i + 1]);
if (min < 0 || d < min) {
@fntlnz
fntlnz / self-signed-certificate-with-custom-ca.md
Last active November 14, 2024 10:34
Self Signed Certificate with Custom Root CA

Create Root CA (Done once)

Create Root Key

Attention: this is the key used to sign the certificate requests, anyone holding this can sign certificates on your behalf. So keep it in a safe place!

openssl genrsa -des3 -out rootCA.key 4096
@RobertKolner
RobertKolner / disable_signals.py
Last active August 15, 2018 10:11
[Note: for a better version, visit here: https://github.com/RobertKolner/django-signal-disabler] Temporarily disable all signals in django
from collections import defaultdict
from django.db.models.signals import *
class DisableSignals(object):
def __init__(self, disabled_signals=None):
self.stashed_signals = defaultdict(list)
self.disabled_signals = disabled_signals or [
pre_init, post_init,
pre_save, post_save,