Skip to content

Instantly share code, notes, and snippets.

View jarshwah's full-sized avatar

Josh Smeaton jarshwah

View GitHub Profile
@jarshwah
jarshwah / launch.json
Created April 23, 2017 11:28
Webpack Source Maps with vscode debugging
// debug config for running project under vscode debugger
{
"version": "0.2.0",
"configurations": [
{
"trace": true,
"name": "Chrome Debug",
"type": "chrome",
"request": "launch",
"url": "http://localhost:8000/",
@jarshwah
jarshwah / models.py
Created December 21, 2022 22:04
annotating your manager for useful type hints
class MyModel(models.Model):
name = models.CharField()
objects: models.QuerySet["MyModel"]
MyModel.objects.filter().first()
@jarshwah
jarshwah / object_cache.py
Created July 12, 2017 14:01
Django LRU in memory cache backend
# -*- coding: utf-8 -*-
from __future__ import absolute_import, print_function, unicode_literals
import time
from contextlib import contextmanager
from django.core.cache.backends.base import DEFAULT_TIMEOUT, BaseCache
from django.utils.synch import RWLock
from lru import LRU # dependency: pip install lru-dict
@jarshwah
jarshwah / boxstarter.ps1
Last active May 26, 2020 01:56
Box Starter - VS2015 Dev
# From a command prompt:
# START http://boxstarter.org/package/nr/url?https://gist.githubusercontent.com/jarshwah/58f5f9f78d43ae269545/raw/e5a2076fbe76106b19ecaa62355776aa0a02fc91/boxstarter.ps1
# Boxstarter options
$Boxstarter.RebootOk=$true # Allow reboots?
$Boxstarter.NoPassword=$false # Is this a machine with no login password?
$Boxstarter.AutoLogin=$true # Save my password securely and auto-login after a reboot
# Basic setup
Update-ExecutionPolicy Unrestricted
def pytest_configure(config):
config.addinivalue_line(
"markers", "enable_inline_css: run css postprocessing over generated emails"
)
@pytest.fixture(autouse=True)
def disable_inline_css(request, monkeypatch):
if "enable_inline_css" in request.keywords:
return
#!/bin/bash
# ~/.osx — http://mths.be/osx
# Close any open System Preferences panes, to prevent them from overriding
# settings we’re about to change
osascript -e 'tell application "System Preferences" to quit'
# Ask for the administrator password upfront
import pickle
import six
from django_redis.serializers.pickle import PickleSerializer
def compat_pickle_loads(value, **kwargs):
if six.PY2:
return _py2_pickle_loads(value)
return _py3_pickle_loads(value, **kwargs)
@jarshwah
jarshwah / tests.py
Last active June 7, 2019 12:41
Unit test for confirming there are no outstanding migrations
from django.core.management import call_command
from django.test import TestCase
class MigrationsTestCase(TestCase):
def test_no_outstanding_migrations(self):
"""No migrations need to be generated"""
try:
result = call_command("makemigrations", "--dry-run", "--check", "--no-input", "-v", "0")
except SystemExit:
self.fail("There were outstanding migrations")
@jarshwah
jarshwah / rabbitmq_to_cloudwatch.sh
Created June 5, 2019 13:23
Send RabbitMQ queue length to Cloudwatch
#! /bin/bash
# This script reads rabbitmq statistics and report them as CloudWatch metrics.
# https://gist.github.com/GoodMirek/2dc39100d18c72eed3f0f3569e221f4f
# RabbitMQ::messages_ready
# RabbitMQ::messages_unacknowledged
# RabbitMQ::consumers
# Dimensions: QueueName, InstanceId, VHost
@jarshwah
jarshwah / Create Postgres Django DB
Last active October 13, 2018 20:24
Creating testing databases for django on Postgres 9.3 for OSX (installed with homebrew)
# Note that the "smeatonj" below is the user that installed postgres with homebrew
# first, the "default" database:
$ createuser -U smeatonj djangotest -P
Enter password for new role:
Enter it again:
$ createdb djangotest
$ psql -U smeatonj -d djangotest