This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Mark Allan B. Meriales | |
A command tool that generates fixture data (json) | |
based from existing Models. This can be helpful when | |
doing testing. | |
""" | |
from django.core.management.base import BaseCommand | |
from django.db import models |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get_max_combination(length, base=16): | |
current = base**(length-1) | |
next = base**(length) | |
return next-current |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
def get_random_hex_by_length(length=4): | |
"""Returns a random hex code according to length""" | |
return hex(random.randint((16**((length)-1)),(16**length)))[2:] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import threading | |
import re | |
from django.conf import settings | |
from django.http import HttpResponseRedirect | |
from django.contrib import messages | |
from django.utils.translation import ugettext as _ | |
# prevent python threading issue, use threading.local to instead of global var |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Mark Allan B. Meriales | |
# Client testing basic | |
# If you want to generate fixtures out of your | |
# existing models and database contents you may | |
# try my manage.py command below | |
# https://gist.github.com/makmac213/4671624 | |
import unittest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
UPDATE users | |
SET username = Substring(username, 1, Charindex('@', username)) | |
+ 'mailcatch.com' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
__author__ = 'Mark Allan B. Meriales' | |
from selenium.common.exceptions import NoSuchElementException | |
# Routine for finding, clicking, clearing and sending keys | |
# to an element | |
def click_clear_send_keys(elem, keys, **kwargs): | |
if kwargs.get('click', False): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Mark Allan B. Meriales | |
def ordinal_date_suffix(dt): | |
suffix = '' | |
num_date = int(dt.strftime('%d')) | |
if (num_date >= 4 and num_date <= 20) or (num_date >= 24 and num_date <= 30): | |
suffix = 'th' | |
else: | |
suffix = ['st','nd','rd'][(num_date % 10) - 1] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# the javascript # | |
""" | |
var position = -1; | |
$(function(e) { | |
$("#sortable").sortable({ | |
start: function(event, ui) { | |
position = ui.item.index(); | |
}, | |
stop: function(event, ui) { | |
//alert("New position: " + ui.item.index()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
from django.conf import settings | |
from django.shortcuts import HttpResponse | |
from django.template import RequestContext | |
from bar.models import Bar | |
from foo.models import Foo | |
OlderNewer