Skip to content

Instantly share code, notes, and snippets.

@chris-ramon
chris-ramon / django.sh
Last active October 13, 2015 10:38
django commands
# export data
./manage.py dumpdata --indent=2 auth > initial_data.json
# no input
./manage.py syncdb --noinput
# load any fixture, which should be whitin a dir called fixture within some django app
./manage.py loaddata shipping_fixture.json
# migrations
@chris-ramon
chris-ramon / calculator.py
Created December 2, 2012 01:18
calculator
# -*- coding: utf-8 -*-
import unittest
class Calculadora(object):
def __init__(self, x=None, y=None):
self.x = x
self.y = y
def suma(self):
return self.x + self.y
def resta(self):
return self.x - self.y
@chris-ramon
chris-ramon / bash.sh
Created December 6, 2012 02:28
mongodb installation
# giving permissions
sudo chown $USER /data/db
# change /data/db owner
sudo chown $USER /data/db
@chris-ramon
chris-ramon / ordenamiento.py
Created December 6, 2012 06:52
hw1 - tekfarmers.
# -*- coding: utf-8 -*-
import unittest
class Ordenamiento(object):
def __init__(self, numeros=None):
self.numeros = numeros
def insertion_sort(self):
# Tu código va aquí.
return self.numeros
class OrdenamientoTest(unittest.TestCase):
@chris-ramon
chris-ramon / sublime.json
Last active October 13, 2015 18:58 — forked from abrookins/gist:1933635
sublime build
// path of the file to override: /home/user/.config/sublime-text-2/Packages/Python/Python.sublime-build
// for simple scripts using virtualenv
{
"cmd": ["python", "-u", "$file"],
"env": {"PYTHONPATH": "/home/chris/venvs/venv-authorize-sauce/lib/python2.7/site-packages"},
"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
"selector": "source.python"
}
@chris-ramon
chris-ramon / sublimetext2.js
Created December 8, 2012 19:34
sublime text 2 custom keymap
[
{ "keys": ["alt+1"], "command": "toggle_side_bar" },
{ "keys": ["alt+2"], "command": "show_overlay", "args": {"overlay": "goto", "text": "@"} },
{ "keys": ["alt+m"], "command": "toggle_minimap" },
{ "keys": ["alt+right"], "command": "next_view" },
{ "keys": ["alt+left"], "command": "prev_view" }
]
from apps.rp.models.Permission import CustomPermission
CustomPermission.patch_model_attributes()
from django.contrib.auth.models import Permission
from django.db import models
class CustomPermission(object):
@classmethod
def patch_model_attributes(cls):
method = getattr(Permission, 'add_to_class')
@chris-ramon
chris-ramon / url_patterns.py
Created December 11, 2012 16:26 — forked from c4urself/url_patterns.py
url django
(r'^articles/(?P<year>\d{4}/?$, 'main.views.year'),
# When a use case comes up that a month needs to be involved as
# well, you add an argument in your regex:
(r'^articles/(?P<year>\d{4}/(?P<month>\d{2})/?$, 'main.views.year_month'),
# That works fine, unless of course you want to show something
# different for just the year, in which case the following case can be
# used, making separate views based on the arguments as djangoproject
@chris-ramon
chris-ramon / aggregation-mongodb
Created December 16, 2012 18:17
aggregation framework mongodb
#http://docs.mongodb.org/manual/reference/sql-aggregation-comparison/
@chris-ramon
chris-ramon / django.py
Created January 17, 2013 20:08
import django.
#! /usr/bin/env python
#coding:utf-8
import sys
import os
sys.path.insert(0, os.path.expanduser('/home/chris/Projects/royalpioneers'))
os.environ['DJANGO_SETTINGS_MODULE'] = 'royal.settings'
from django.contrib.contenttypes.models import ContentType