Skip to content

Instantly share code, notes, and snippets.

View makmac213's full-sized avatar

Mark Allan B. Meriales makmac213

View GitHub Profile
@makmac213
makmac213 / model_to_fixture.py
Last active December 11, 2015 22:48
A command tool that generates fixture data (json) based from existing Models. This can be helpful when doing testing.
"""
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
def get_max_combination(length, base=16):
current = base**(length-1)
next = base**(length)
return next-current
@makmac213
makmac213 / get_random_hex_by_length.py
Last active December 11, 2015 22:48 — forked from markmeriales/gist:4058523
Return a random hex code
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:]
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
@makmac213
makmac213 / basic_client_tests.py
Last active December 12, 2015 04:09
Just some few basics for me on learning tests.
# 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
@makmac213
makmac213 / dummy_emails.sql
Created February 11, 2013 02:35
Change email addresses to test emails.
UPDATE users
SET username = Substring(username, 1, Charindex('@', username))
+ 'mailcatch.com'
@makmac213
makmac213 / routine.py
Created March 8, 2013 08:26
For Selenium routine actions
# -*- 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):
@makmac213
makmac213 / ordinal_date_suffix.py
Last active December 16, 2015 21:39
returns the date with ordinal suffix
# 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]
# 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());
@makmac213
makmac213 / Ala Pinterest
Created October 10, 2013 06:03
For random multiple classes query (ala pinterest)
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