Skip to content

Instantly share code, notes, and snippets.

View jarshwah's full-sized avatar

Josh Smeaton jarshwah

View GitHub Profile
@jarshwah
jarshwah / shell.sh
Created November 17, 2015 02:40
Timing python moving if outside loop
smeatonj ~/Development
$ python3 -m timeit -s 'from testif import without_if' 'without_if(0, 100)'
100000 loops, best of 3: 4.94 usec per loop
smeatonj ~/Development
$ python3 -m timeit -s 'from testif import with_if' 'with_if(0, 100)'
100000 loops, best of 3: 5.88 usec per loop
smeatonj ~/Development
$ python3 -m timeit -s 'from testif import without_if' 'without_if(0, 10000)'
Error: Could not retrieve catalog from remote server: Error 400 on SERVER: Failed to parse template uwsgi/uwsgi.ini.erb:
Filepath: /etc/puppet/modules/uwsgi/templates/uwsgi.ini.erb
Line: 16
Detail: undefined method `sort_by' for #<String:0x2a4870f8>
at /etc/puppet/modules/uwsgi/manifests/init.pp:148 on node node.domain.com
Warning: Not using cache on failed catalog
Error: Could not retrieve catalog; skipping run
@jarshwah
jarshwah / SearchVector.py
Created April 4, 2016 00:30
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])]
@jarshwah
jarshwah / main-window.cs
Created June 9, 2016 00:04
Register a top level tab in workspace
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 / uwsgi-conf.ini
Created August 1, 2016 10:37
Config files for deploying django
# 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
- 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 / 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 / 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
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 / suspendingreceiver.py
Created August 23, 2018 12:04
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`.