Skip to content

Instantly share code, notes, and snippets.

Josh Smeaton jarshwah

Block or report user

Report or block jarshwah

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
jarshwah /
Last active Jun 7, 2019
Unit test for confirming there are no outstanding migrations
from import call_command
from django.test import TestCase
class MigrationsTestCase(TestCase):
def test_no_outstanding_migrations(self):
"""No migrations need to be generated"""
result = call_command("makemigrations", "--dry-run", "--check", "--no-input", "-v", "0")
except SystemExit:"There were outstanding migrations")
jarshwah /
Created Jun 5, 2019
Send RabbitMQ queue length to Cloudwatch
#! /bin/bash
# This script reads rabbitmq statistics and report them as CloudWatch metrics.
# RabbitMQ::messages_ready
# RabbitMQ::messages_unacknowledged
# RabbitMQ::consumers
# Dimensions: QueueName, InstanceId, VHost
jarshwah /
Created Aug 23, 2018
Prevent receivers from running in test suites
import functools
from django.conf import settings
from django.dispatch import receiver
def suspendingreceiver(signal, **decorator_kwargs):
A wrapper around the standard django receiver that prevents the receiver
from running if the setting `SUSPEND_SIGNALS` is `True`.
View webpack.babel.js
module: {
rules: [
// ...
// Rules for Style Sheets
test: /\.(scss|sass)$/,
include: [path.resolve(__dirname, 'src'), path.resolve(__dirname, 'assets/scss')],
use: extractSass.extract({
use: [
// Process internal/project styles (from assets/scss folder)
jarshwah /
Created Jul 12, 2017
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 / launch.json
Created Apr 23, 2017
Webpack Source Maps with vscode debugging
View launch.json
// 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/",
View ansible contortions
- name: create aliases for executing tests on regular database backends
dest: "{{ user_home}}.profile"
line: >
alias runtests{{ (10 * item.0)|round|int }}-{{ item.1 }}='PYTHONPATH=/home/vagrant/djangodata/
tox -c /django/tox.ini -e py{{ (10 * item.0)|round|int }}{{ ("-" + item.1)|replace("-sqlite3", "") }} --
--settings=test_{{ item.1 }}'
- '{{ python_versions }}'
- '{{ databases }}'
jarshwah / uwsgi-conf.ini
Created Aug 1, 2016
Config files for deploying django
View uwsgi-conf.ini
# Some of the filenames have been named to make things slightly easier to understand
# uwsgi parameters that instruct uwsgi how to run
# the wsgi file that django generates for your project
# nginx config connects to the uwsgi unix socket
jarshwah / main-window.cs
Created Jun 9, 2016
Register a top level tab in workspace
View main-window.cs
if (options.SingleInstance) // hosted within the main window
container.RegisterType<ICRMViewModel, CRMViewModelSingleInstance>(Singleton);
new ViewActivator { ViewType = typeof(ICRMView), ViewName = "CRMView", ActivateView = true });
jarshwah /
Created Apr 4, 2016
Use inner expressions
class ConcatWords(Func):
arg_joiner = " || ' ' || "
template = '%(expressions)s'
class SearchVector(SearchVectorCombinable, Func):
function = 'to_tsvector'
_output_field = SearchVectorField()
def __init__(self, *expressions, **extra):
expressions = [ConcatWords(*[Coalesce(expression, Value('')) for expression in expressions])]
You can’t perform that action at this time.