Skip to content

Instantly share code, notes, and snippets.

View alee's full-sized avatar

Allen Lee alee

View GitHub Profile
@alee
alee / views.py
Last active March 24, 2024 19:00
example Django view function that can be used for Discourse SSO, i.e., Discourse delegates User authentication to Django
import base64
import hmac
import hashlib
from urllib import parse
from django.contrib.auth.decorators import login_required
from django.http import HttpResponseBadRequest, HttpResponseRedirect
from django.conf import settings
@login_required
@alee
alee / against-globals.md
Created June 15, 2018 23:04 — forked from nicolaspayette/against-globals.md
Why you should probably avoid global variables in NetLogo

In my experience, a disproportionate amount of bugs in NetLogo models are caused by the mismanagement of global variables.

Here are a few reasons why I think that is the case, in (roughly) decreasing order of importance:

  • Code is not just a way of getting the computer to do what you want it to do—it is a way of conveying meaning to the reader of your code. When you declare a global variable, the meaning you convey is: “Hey! This thing is important throughout the whole program. You should always be paying attention to it.”

    Sometimes it’s justified , but very often, it is not. An unjustified global is not only failing to convey the right message: it’s actively misleading.

When I approach a model’s code for the first time, the first thing I do is look at the declarations on top: what breeds do we have, what agent variables do we have, and what global variables do we have? That gives me the “big picture” and tells me what I should be paying attention to when trying to understand what the code is do