Skip to content

Instantly share code, notes, and snippets.

View xpostudio4's full-sized avatar

Leonardo xpostudio4

View GitHub Profile
@xpostudio4
xpostudio4 / original.py
Created October 4, 2016 18:48
Refactoring: Growing Software like a Gardener
@login_required(redirect_field_name="/")
def uploaded_pictures(request):
pictures = AdPicture.objects.filter(user=request.user, ad__isnull=True)
json_pics = [{'name': pic.picture.name.split("/")[-1],
'uuid': pic.uuid,
'size': pic.picture.size,
'thumbnailUrl': pic.picture.url} for pic in pictures]
return JsonResponse(json_pics, safe=False)
@xpostudio4
xpostudio4 / extending0.py
Last active October 4, 2016 17:53
Refactoring: Growing Software like a Gardener
class SimpleGradebook(object):
def __init__(self):
self.__grades = {}
def add_student(self, name):
self._grades[name] = []
def report_grade(self, name, score):
self._grades[name].append(score)
@xpostudio4
xpostudio4 / example2a.java
Created October 4, 2016 17:10
Refactoring: Growing Software like a Gardener
class Person..
public String getName(){
return _name;
}
public String getTelephoneNumber() {
return ("(" + _officeAreaCode + ")" + _officeNumber);
}
public getOfficeAreaCode(){
@xpostudio4
xpostudio4 / decorators_cheat_sheet.py
Last active September 20, 2016 16:49
Decorators Cheat Sheet
import functools # Part of Python standard library
def decorator(wrapped_function):
def _wrapper(*args, **kwargs):
# do something before the function call
result = wrapped_function(*args, **kwargs)
# do something after the function call
return result
return _wrapper

Wagtail tutorial

Thanks to [Serafeim Papastefanos] for authoring this tutorial. Please note that the installation process is in flux; most of the steps here should soon be unnecessary.

[Wagtail] is a new Open Source [Django]-based CMS. In this 20 minute tutorial we will see how you can create a blog from scratch using Wagtail. If you want to see some more examples of usage please take a look at the [wagtaildemo] GitHub project.

To follow this tutorial you will need to have [Python] 2.7 installed with a working version of [pip] and [virtualenv].

Installing the wagtail dependencies

@xpostudio4
xpostudio4 / gist:7680855
Last active December 29, 2015 13:59
Custom User Model Django
#models.py
#Stdlib imports
import datetime
#Django core Imports
from django.db import models
from django.contrib.auth.models import (
BaseUserManager, AbstractBaseUser, PermissionsMixin
)
@xpostudio4
xpostudio4 / Rails_cheatsheet.md
Last active September 20, 2015 01:59 — forked from freqn/Rails cheatsheet
Rails cheatsheet

Getting Started Reference

Rails new

Basic usage:

$ rails new <app_name>

This will create a directory named: <app_name> that contains a brand new rails app folder structure and boilerplate files.

@xpostudio4
xpostudio4 / index.md
Last active September 19, 2015 08:59 — forked from rstacruz/index.md
Rails models cheatsheet

Rails Models

Generating models

$ rails g model User

Associations

belongs_to

has_one

class MyCommonlyUsedModel(models.Model):
class Meta:
managed = False
db_table = 'app_largetable'
f1 = models.Field(...)
f2 = models.Field(...)
# A model that allows the migrations framework to also manage the table
# Not sure if this actually works, but would allow for a more DRY approach
class MyManagedModel(MyCommonlyUsedModel):