Skip to content

Instantly share code, notes, and snippets.

View jarshwah's full-sized avatar

Josh Smeaton jarshwah

View GitHub Profile
@jarshwah
jarshwah / backend.py
Last active August 29, 2015 14:11
Django Custom Auth Backend - if refactored
import base64
import hashlib
import hmac
import requests
import time
from django.contrib.auth import get_user_model
from django.conf import settings
from django.core.cache import cache
from django.utils.http import unquote
@jarshwah
jarshwah / func_as_transform.diff
Created December 20, 2014 08:44
Making func expressions into Transforms
diff --git django/db/models/functions.py django/db/models/functions.py
index c3dea1f..30046ea 100644
--- django/db/models/functions.py
+++ django/db/models/functions.py
@@ -2,7 +2,7 @@
Classes that represent database functions.
"""
from django.db.models.expressions import Func, Value
-from django.db.models import IntegerField
+from django.db.models import IntegerField, Transform
@jarshwah
jarshwah / update-djangocore-box
Last active August 29, 2015 14:12
Update djangocore-box VM to run py3.3 tests properly
sudo apt-get update
sudo apt-get install gcc libffi-dev vim
sudo apt-get install python3.3 python3.3-dev python3.3-minimal
workon py2.7
pip install -r /home/vagrant/.hosthome/Development/django/tests/requirements/py2.txt
deactivate
rm /home/vagrant/.virtualenvs/py3.3/bin/python
cd /home/vagrant/.virtualenvs/
mkvirtualenv py3.3 --python=`which python3.3`
workon py3.3
@jarshwah
jarshwah / case_expressions.diff
Last active August 29, 2015 14:12
Fixes problems with oracle, cast issues with postgres, and removes depending on the type of compiler
diff --git a/django/db/models/expressions.py b/django/db/models/expressions.py
index 64b5ba0..8b69406 100644
--- a/django/db/models/expressions.py
+++ b/django/db/models/expressions.py
@@ -487,11 +487,7 @@ class Value(ExpressionNode):
def as_sql(self, compiler, connection):
val = self.value
if self._output_field_or_none is not None:
- from django.db.models.sql.compiler import SQLUpdateCompiler
- if isinstance(compiler, SQLUpdateCompiler):
@jarshwah
jarshwah / branch-oracle.sql
Created January 6, 2015 01:34
Compare queries
-- queries.tests.Queries1Tests.test_ticket2496
SELECT * FROM (
SELECT "_SUB".*,
ROWNUM AS "_RN" FROM (SELECT "QUERIES_ITEM"."ID",
"QUERIES_ITEM"."NAME",
"QUERIES_ITEM"."CREATED",
"QUERIES_ITEM"."MODIFIED",
"QUERIES_ITEM"."CREATOR_ID",
"QUERIES_ITEM"."NOTE_ID",
"QUERIES_AUTHOR"."ID",
@jarshwah
jarshwah / fix-attempt.diff
Last active August 29, 2015 14:12
oracle fix notes
diff --git a/django/db/backends/oracle/compiler.py b/django/db/backends/oracle/compiler.py
index cfc8a08..12d9ad6 100644
--- a/django/db/backends/oracle/compiler.py
+++ b/django/db/backends/oracle/compiler.py
@@ -20,12 +20,12 @@ class SQLCompiler(compiler.SQLCompiler):
do_offset = with_limits and (self.query.high_mark is not None
or self.query.low_mark)
if not do_offset:
- sql, params = super(SQLCompiler, self).as_sql(with_limits=False,
- with_col_aliases=with_col_aliases)
diff --git a/tests/foreign_object/models.py b/tests/foreign_object/models.py
index e774421..1c163f5 100644
--- a/tests/foreign_object/models.py
+++ b/tests/foreign_object/models.py
@@ -278,7 +278,7 @@ class BrokenContainsRelation(StartsWithRelation):
@python_2_unicode_compatible
class SlugPage(models.Model):
- slug = models.TextField()
+ slug = models.CharField(max_length=20)
import random
def simulate(bank=1000.0, percentage=2.0, races=10000):
min_odds = 2.4
max_odds = 13.0
sample_odds = [3,6,21,5.5,5.5,5,2.8,18,8,6.5,4,3.3,2.4,21,5,3.2,3.3,6.5,5.5,16,3.4,26]
original_bank = bank
want_to_win = (percentage / 100) * bank
races_run = 0
wins = 0
cinst Atom -y
cinst cmder -y
cinst git -y
cinst git.install -y
cinst git-credential-winstore -Version 1.2.0.0 -y
cinst resharper -y
cinst sysinternals -y
cinst Devbox-Clink -y
cinst linqpad4 -y
cinst SublimeText3 -y
@jarshwah
jarshwah / Change Restore.diff
Created October 12, 2015 00:16
ConcatPair.coalesce() idempotent
diff --git a/django/db/models/functions.py b/django/db/models/functions.py
index ac24aa7..8139ec0 100644
--- a/django/db/models/functions.py
+++ b/django/db/models/functions.py
@@ -44,8 +44,12 @@ class ConcatPair(Func):
def as_sqlite(self, compiler, connection):
self.arg_joiner = ' || '
self.template = '%(expressions)s'
- self.coalesce()
- return super(ConcatPair, self).as_sql(compiler, connection)