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
@gladson
gladson / gist:1472907
Created December 13, 2011 16:53
uploads
<!DOCTYPE html>
<html>
<head>
<title> jQuery Youtube </title>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" >
<link rel="stylesheet" href="../../reset.css" type="text/css" media="screen" charset="utf-8">
<link rel="stylesheet" href="../../screen.css" type="text/css" media="screen" charset="utf-8">
<link rel="stylesheet" href="screen.css" type="text/css" media="screen" charset="utf-8">
@gladson
gladson / gist:1512659
Created December 23, 2011 01:21
delete imagem django
from django.core.files.storage import default_storage
def delete_image_update_view(self, request):
qs = self.get_object(queryset=self.model.objects.all())
if qs and request.FILES.get(key='image', default=None):
try:
cur_file = self.model.objects.get(pk=qs.pk)
default_storage.delete(cur_file.image.path)
@gladson
gladson / gist:1541450
Created December 30, 2011 21:00
sql to django queryset cheatsheet by pythonnewbie
Sql QuerySet Notes
SELECT count(*) FROM fruit Fruits.objects.count() table count
SELECT count(*) FROM fruit WHERE name=’Orange’ Fruits.objects.filter(name__exact=’Orange’).count() count with filter
SELECT * FROM fruit WHERE color is NULL Fruits.objects.get(color__isnull=True) filter by null
SELECT * FROM fruit WHERE color is NOT NULL Fruits.objects.get(color__isnull=False) filter by null
SELECT * FROM fruit WHERE name=’Apple’ Fruits.objects.get(name__exact=’Apple’) case sensitive
SELECT * FROM fruit WHERE lower(name)=lower(‘Apple’) Fruits.objects.get(name__iexact=’Apple’) case in-sensitive
SELECT * FROM fruit WHERE name LIKE ‘App%’ Fruits.objects.filter(name__startswith=’App’) case sensitive LIKE
SELECT * FROM fruit WHERE upper(name) LIKE ‘APP%’ Fruits.objects.filter(name__ista
@gladson
gladson / gist:1563059
Created January 5, 2012 00:34
Generic Views by Flavia missi
# Simple json response generic view
from django.views.generic import View
from django.utils import simplejson
class JSONResponseView(View):
def render_to_response(self, data, **httpresponse_kwargs):
"Retuns a json response based on the context"
json_data = simplejson.dumps(data)
@gladson
gladson / gist:1563556
Created January 5, 2012 03:25
SQL gerado pela queryset a partir do atributo "query" de uma queryset - by Andrews Medina
>>> from django.contrib.auth.models import *
>>> print User.objects.all().query
SELECT "auth_user"."id", "auth_user"."username", "auth_user"."first_name", "auth_user"."last_name", "auth_user"."email", "auth_user"."password", "auth_user"."is_staff", "auth_user"."is_active", "auth_user"."is_superuser", "auth_user"."last_login", "auth_user"."date_joined" FROM "auth_user"
>>> print User.objects.filter(username='andrews').query
SELECT "auth_user"."id", "auth_user"."username", "auth_user"."first_name", "auth_user"."last_name", "auth_user"."email", "auth_user"."password", "auth_user"."is_staff", "auth_user"."is_active", "auth_user"."is_superuser", "auth_user"."last_login", "auth_user"."date_joined" FROM "auth_user" WHERE "auth_user"."username" = andrews
>>>
@gladson
gladson / gist:2720957
Created May 17, 2012 19:04
Quick python weather script using Google's Weather API by git://gist.github.com/2689784.git
#!/usr/bin/env python
# encoding: utf-8
import sys
from argparse import ArgumentParser
from xml.dom import minidom
try:
from urllib.request import urlopen
from urllib.parse import urlencode
except ImportError:
@gladson
gladson / nginx_clip-2.conf
Created May 28, 2012 22:08
gunicorn_clip-2.sh
#! /bin/bash
set -e
LOGFILE=/home/sites-clip/clip-2/logs/gunicorn_clip-2.log
LOGDIR=$(dirname $LOGFILE)
PIDFILE=/home/sites-clip/clip-2/tmp/gunicorn_clip-2.pid
# Number of worker processes.
# Should be no less than the number of cores available and a popular formula
# is 1 + 2 * number of cores.
NUM_WORKERS=3
@gladson
gladson / gist:2883824
Created June 6, 2012 18:43
webserver
import urllib
URL = "http://webservices.daehosting.com/services/eleventest.wso/IsAllNumbers"
numero = ""
XML = """\
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
@gladson
gladson / gist:2952424
Created June 19, 2012 05:18
login.js
<script type="text/javascript">
$(function(){
$('#enviar_contato').click(function(){
var id_username = $("#id_username").val();
var id_password = $("#id_password").val();
var id_token = $("#id_token").val();
if (id_username!='' & id_password!='' & id_token!='')
{
$('.loading').show();
$('form')[0].reset();
@gladson
gladson / gist:3013632
Created June 28, 2012 20:13
DJANGO: grappelli, filebrowser
setinsgs.py
MEDIA_ROOT = os.path.join(PROJECT_ROOT_PATH, 'media')
MEDIA_URL = '/media/'
STATIC_ROOT = os.path.join(PROJECT_ROOT_PATH, 'media/admin')
STATIC_URL = '/media/admin/'
ADMIN_MEDIA_PREFIX = STATIC_URL + 'grappelli/'
urls.py