Skip to content

Instantly share code, notes, and snippets.

View kingbuzzman's full-sized avatar

Javier Buzzi kingbuzzman

View GitHub Profile
@kingbuzzman
kingbuzzman / refere.py
Created February 17, 2011 20:49
session refer.py
class MainsiteMiddleware(object):
def process_request(self, request):
from mainsite.urls import urlpatterns
current_path = request.META.get('PATH_INFO', '')
inside_mainsite = False
# loop over all the page of mainsite
for url in urlpatterns:
# check to see if there is a url match
@kingbuzzman
kingbuzzman / here_is_sorethumb.py
Created March 30, 2011 18:12
What took Robert a week to implement i did in 10 minutes...
def get_dimensions(self, width=None, height=None):
"""
Resize the /images/clients/raw image to whatever dimensions needed, caches the already created images
"""
# default dimentions
height = height or self.image.height
width = width or self.image.width
filename = str(self.image.path)
new_path = filename.replace('/raw/', '/{0}x{1}/'.format(width,height))
@kingbuzzman
kingbuzzman / __init__.py
Created May 22, 2011 02:46
__init__.py
from django.db.models.signals import post_syncdb
from django.contrib.auth import models as auth_models
def fix_db(sender, **kwargs):
from django.db import connection, transaction
cursor = connection.cursor()
# Data modifying operation - commit required
print '* Better the auth_user table'
cursor.execute("ALTER TABLE auth_user ALTER COLUMN username TYPE VARCHAR(255);")
@kingbuzzman
kingbuzzman / gist:1164207
Created August 23, 2011 02:44 — forked from voodootikigod/gist:1155790
PyCodeConf Ticket Give-away
Day job: Java Engineer (Play! framework)
Favorite Python project: PIL (django 2nd favorite)
Favorite Conference: superconf (only one i've ever been to)
Python Experience Level: Average :/
@kingbuzzman
kingbuzzman / example1.html
Created August 23, 2011 19:56
Pure JS implementation
<!DOCTYPE html>
<html>
<head>
<title>Example 1</title>
<script type="text/javascript">
function updateOrder(){
var items = document.getElementById("items");
var itemLabels = document.getElementById("label_items");
var total = 0;
@kingbuzzman
kingbuzzman / example2.html
Created August 23, 2011 19:57
jQuery implementation.. still sucky..
<!DOCTYPE html>
<html>
<head>
<title>Example 2</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.js" type="text/javascript" charset="ISO-8859-1"></script>
<script type="text/javascript">
$(document).ready(function(){
$("#name,#phone,#items").live("change", function(){
var items = $("#items");
var itemLabels = $("#label_items");
@kingbuzzman
kingbuzzman / example3.html
Created August 23, 2011 19:57
Big guns.. knockout has arrived
<!DOCTYPE html>
<html>
<head>
<title>Example 3.a</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.js" type="text/javascript" charset="ISO-8859-1"></script>
<script src="https://raw.github.com/jquery/jquery-tmpl/master/jquery.tmpl.min.js" type="text/javascript"></script>
<script src="http://github.com/downloads/SteveSanderson/knockout/knockout-1.2.1.js" type="text/javascript" charset="ISO-8859-1"></script>
<script type="text/javascript">
$(document).ready(function(){
var viewController = {
@kingbuzzman
kingbuzzman / example3-rightway.html
Created August 23, 2011 19:58
knockout -- how you should really do it.
<!DOCTYPE html>
<html>
<head>
<title>Example 3.b</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.js" type="text/javascript" charset="ISO-8859-1"></script>
<script src="https://raw.github.com/jquery/jquery-tmpl/master/jquery.tmpl.min.js" type="text/javascript"></script>
<script src="http://github.com/downloads/SteveSanderson/knockout/knockout-1.2.1.js" type="text/javascript" charset="ISO-8859-1"></script>
<script type="text/javascript">
$(document).ready(function(){
// controller
@kingbuzzman
kingbuzzman / update.js
Created December 22, 2011 19:34
update for Backbone.Collection
update: function(options){
options = options || {};
var collection = this, success = options.success;
options.success = function(resp, status, xhr){
var changed = false;
var collectionIds = []; // store the ids as we add them
var toDelete = []; // store all the models to remove
var onChange = function() {
@kingbuzzman
kingbuzzman / Dockerfile
Created March 27, 2017 15:32
Fix alpine django
....
RUN pip install .... django ...
# Fixes bug that is being thrown by postgres interacting with ldap (see http://stackoverflow.com/questions/38740631/need-to-pre-import-module-to-avoid-error)
RUN echo -e "--- /usr/local/lib/python2.7/site-packages/django/apps/config.original.py\n+++ /usr/local/lib/python2.7/site-packages/django/apps/config.py\n@@ -104,6 +104,7 @@\n else:\n try:\n # If this works, the app module specifies an app config class.\n+ if entry == 'django.contrib.postgres': import ldap\n entry = module.default_app_config\n except AttributeError:\n # Otherwise, it simply uses the default app config class." > /tmp/config.py.patch
RUN cd /usr/local/lib/python2.7/site-packages/django/apps/ && patch config.py /tmp/config.py.patch
...