Skip to content

Instantly share code, notes, and snippets.

@kipanshi
kipanshi / gist:2480979
Created April 24, 2012 15:57
My fist MIPS Assembly programm
# 1.s
#
# My first MIPS Assembly program
# This program let you input 2 numbers and output the result of addition
.data
prompt_msg: .asciiz "Enter two numbers to add:\n"
result_msg: .asciiz "Result: "
end_of_line: .asciiz "\n"
@kipanshi
kipanshi / gist:2413788
Created April 18, 2012 14:00
Mock datetime.now() for testing
class FakeDatetimeFactory(object):
"""Factory to help testing logic depending on ``datetime.now()``.
"""
@classmethod
def now(self, *args, **kwargs):
class FakeDatetime(datetime):
"""Datetime class with overriden ``now()`` method."""
@kipanshi
kipanshi / trafaret_tutorial.py
Created March 12, 2012 20:20 — forked from Deepwalker/gist:2023370
Trafaret Tutorial
def trafaret_tutorial():
"""
So, you have some structure from wild. Say this will be some JSON over API.
But you cant change this JSON structure.
"""
sample_data = {
'userNameFirst': 'Adam',
'userNameSecond': 'Smith',
'userPassword': 'supersecretpassword',
'userEmail': '[email protected]',
@kipanshi
kipanshi / gist:1951748
Created March 1, 2012 18:07
Pretty Django models updating
def update(instance, **kwargs):
"""Helper to update instance of the model with data from kwargs."""
instance.__class__.objects.filter(pk=instance.pk).update(**kwargs)
@kipanshi
kipanshi / gist:1672996
Created January 24, 2012 22:04
Reduce + Replace
REPLACE_MAP = (
('project_dir', project_dir),
('user', user)
)
TEMPLATE = '{{ %s }}'
for line in source.readlines():
dest.write(
reduce(
@kipanshi
kipanshi / gist:1520747
Created December 26, 2011 08:13
Acessing global namespace
# Assume you have model ``Project`` with 1:M relation to ``Task``
# here ``p`` instance of ``Project``, and it has some amount of tasks
# Following inline is creating global variable ``t<idx>`` for each task (e.g. t1, t2, ...)
[globals().update({'t%s' % (idx + 1): t}) for idx, t in enumerate(p.tasks.all())]
@kipanshi
kipanshi / gist:1519666
Created December 25, 2011 19:50
OrderedCITestSuiteRunner (if you use TransacionTestCase along with TestCase in Django)
import unittest
from django_jenkins.runner import CITestSuiteRunner
from django.test import TestCase
from django.test.simple import reorder_suite
from django_jenkins import signals
class OrderedCITestSuiteRunner(CITestSuiteRunner):
"""
This particular test suite runner do Django test cases ordering,
putting TransactionTestCase to the end.