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
jarshwah / tests.py
Last active Jun 7, 2019
Unit test for confirming there are no outstanding migrations
View tests.py
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 Jun 5, 2019
Send RabbitMQ queue length to Cloudwatch
View rabbitmq_to_cloudwatch.sh
#! /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 / suspendingreceiver.py
Created Aug 23, 2018
Prevent receivers from running in test suites
View suspendingreceiver.py
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
jarshwah / object_cache.py
Created Jul 12, 2017
Django LRU in memory cache backend
View object_cache.py
# -*- 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 / 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
lineinfile:
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 }}'
with_nested:
- '{{ python_versions }}'
- '{{ databases }}'
@jarshwah
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
/path/to/project/uwsgi-conf.ini
# the wsgi file that django generates for your project
/path/to/yourproject/yourproject/wsgi.py
# nginx config connects to the uwsgi unix socket
/etc/nginx/sites-enabled/yourproject.conf
/etc/nginx/conf.d/yourproject_upstream.conf
@jarshwah
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);
viewManager.ViewsByRegionName["ToolbarWorkplaceRegion"].Add(
new ViewActivator { ViewType = typeof(ICRMView), ViewName = "CRMView", ActivateView = true });
}
@jarshwah
jarshwah / SearchVector.py
Created Apr 4, 2016
Use inner expressions
View SearchVector.py
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.