Skip to content

Instantly share code, notes, and snippets.

View gladson's full-sized avatar
😎
Vá lutar pelo que você acredita.

Gladson gladson

😎
Vá lutar pelo que você acredita.
View GitHub Profile
from django import http
from django.conf import settings
"""
Put this file in a directory called, eg, 'middleware,' inside your django
project. Make sure to create an __init__.py file in the directory so it can
be included as a module.
Set the values for
XS_SHARING_ALLOWED_ORIGINS
XS_SHARING_ALLOWED_METHODS
@felipe-prenholato
felipe-prenholato / exemplo_completo
Last active December 15, 2015 08:19
Exemplo usado em lista de discussão para mostrar uma relação com um model e como obter ela sem fazer muita query.
>>> from posts.models import User, Post, Amigos
>>> # Cria joao
>>> joao = User(username="joao", first_name="João", email="[email protected]")
>>> joao.save()
>>> # Cria jose
>>> jose = User(username="jose", first_name="José", email="[email protected]")
>>> jose.save()
@shazron
shazron / anchor_tag_replace_inappbrowser.js
Last active September 17, 2020 17:58
Anchor tag link replace for InAppBrowser (Apache Cordova)
// warning, jQuery code below
$(document).ready(function() {
var $a = $("a");
$a.click(function(x) {
x.preventDefault();
var url = $(this).attr('href');
launchUrl(url); // where launchUrl is your function that calls window.open, etc
});
@perone
perone / time_dict_value_max.py
Created December 4, 2012 00:31
Python max dict value
import timeit
t = timeit.Timer("v=sorted(d.items(), key=lambda x: x[1])[-1]",
"d = {'a': 1000, 'b': 3000, 'c':100}")
print t.timeit()
# 1.648s
t = timeit.Timer("v=max(d.iteritems(), key = operator.itemgetter(1))[0]",
"import operator; d = {'a': 1000, 'b': 3000, 'c':100}")
print t.timeit()
@macndesign
macndesign / gerador.py
Created November 7, 2012 19:46
Redimensiona imagens em vários tamanhos e guarda em um arquivo zip com argparse para passar algumas opções via linha de comando.
# coding: utf-8
import os, re, zipfile, argparse
try:
from PIL import Image
except ImportError:
import Image
def normalizar(valor):
"""
@phloe
phloe / combine-layout.md
Last active July 27, 2020 07:23
combine-layout - float/inline-block layout technique

combine-layout

The following outlines a technique combining floating blocks and inline-blocks allowing for fairly interesting layouts without the need to use nested rows and avoids some problems when using pure floats.

The technique itself only uses three classnames:

  • combine-layout - defines the containing element.
  • break - starts a new row when in floating block context.
  • divide - starts off the inline-block context.
@hersonls
hersonls / middleware.py
Created September 11, 2012 02:35
Middleware for django-subdomains
class SubdomainURLRoutingMiddleware(SubdomainMiddleware):
def process_request(self, request):
super(SubdomainURLRoutingMiddleware, self).process_request(request)
subdomain = getattr(request, 'subdomain', False)
if subdomain is not False and subdomain not in settings.SUBDOMAIN_BLACKLIST:
# Here is the trick. I will put at the first rule the users url
# set at the settings, this way, the first page will be the
# user page matched with subdomain.
@hersonls
hersonls / gist:3695466
Created September 11, 2012 02:22
Nginx and Apache configuration for sub-domains
# Nginx
server {
# [...]
server_name *.yourdomain.com;
# [...]
}
@carlosrberto
carlosrberto / ready.js
Created August 31, 2012 18:34
Background Resize
$(function(){
var image = $('.background');
function resize(){
resizeBackground(image, 640, 480);
}
$(window).resize(resize);
});
@hersonls
hersonls / urls.py
Created August 27, 2012 03:01
Django Urls
from django.conf import settings
from django.conf.urls import patterns, include, url
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
# from django.contrib import admin
# admin.autodiscover()
urlpatterns = patterns('',
# url(r'^admin/doc/', include('django.contrib.admindocs.urls')),