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
@hersonls
hersonls / settings.py
Last active March 15, 2022 16:11
Django Settings
import os
# Project information
PROJECT_PATH = os.path.realpath(os.path.dirname(__file__))
PROJECT_NAME = os.path.basename(PROJECT_PATH)
# Helpers
path = lambda *p: os.path.join(PROJECT_PATH, *p)
# Debug
@HondoOhnaka
HondoOhnaka / ajax_submit.py
Created August 20, 2012 16:17
Simple ajax submit for Django form (specifically admin save and continue editing), reference for handling CSRF Middleware
#via http://ankursethi.in/journal/2012/Aug/19/a-django-admin-wishlist/
# In ajax_submit.js.
# NOTE: I'm not very good at writing idiomatic JavaScript.
# If you think this snippet can be improved, do
# let me know.
# WARNING: this code is meant for demonstration purposes.
# Do not use it in production. It fails on several edge cases
@sepehr
sepehr / jquery.mobile_detect.js
Created August 16, 2012 15:54
JS: jQuery Mobile Browser Detection
/**
* Mobile Browser Detection for jQuery
*
* jQuery.browser.mobile will be true if the browser is a mobile device.
*/
(function(a){jQuery.browser.mobile=/android.+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|meego.+mobile|midp|mmp|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i.test(a)||/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(2
@doobeh
doobeh / gist:3188318
Created July 27, 2012 14:27
Installing WeasyPrint on Windows

Installing WeasyPrint on Windows

WeasyPrint converts HTML including images to PDF, it's cross platform but Windows requires a decent amount of massaging to persuade it to work.

To install Pango and Cairo download the [all in one bundle][GTK] of the GTK+ stack and extract the archive to C:\GTK.

You'll need to add the GTK bin folder to your system path so the various

<div class="yourFancyBoxClass">
{% if success %}
<h2>It Worked!</h2>
{% else %}
<form action="{% url ajax_form %}">
{% form %}
</form>
{% endif %}
</div>
@armonge
armonge / gist:2830057
Created May 29, 2012 19:04
django youtube field
import urlparse
import re
from django.db import models
from django import forms
def validate_youtube_url(value):
'''El patron lo saque de http://stackoverflow.com/questions/2964678/jquery-youtube-url-validation-with-regex'''
pattern = r'^http:\/\/(?:www\.)?youtube.com\/watch\?(?=.*v=\w+)(?:\S+)?$'
@gileno
gileno / gist:2602936
Created May 5, 2012 14:36
Uso do Select Extra
alternatives = Alternative.objects.filter(exercise=exercise)
select_sql = u'''select courses_solveexercise.response
from courses_solveexercise where
courses_solveexercise.user_id=%s and
courses_solveexercise.alternative_id=courses_alternative.id'''
alternatives = alternatives.extra(select=SortedDict([('user_response', select_sql)]),
select_params=[user.id])
.fc {
direction: ltr;
text-align: left; }
.fc table {
border-collapse: collapse;
border-spacing: 0; }
.fc .btn {
line-height: 1.2em; }
html .fc {
@gileno
gileno / crawler.py
Created February 23, 2012 18:09
usando mechanize
# -*- coding: utf-8 -*-
import mechanize
br = mechanize.Browser()
br.open("http://www.bmfbovespa.com.br/opcoes/opcoes.aspx?Idioma=pt-br")
br.select_form(nr=0)
# data/hora yyyy-mm-dd-hh-mm-ss
br["ctl00$contentPlaceHolderConteudo$posicoesAbertoEmp$txtConsultaDataDownload$txtConsultaDataDownload$dateInput"] = "2012-02-22-00-00-00"
@gileno
gileno / ajax.js
Created February 7, 2012 14:13
Ajax com serialize
$(function() {
$("#meu-form").submit(function(e) {
e.preventDefault();
var data = $(this).serialize();
$.ajax( {
url: "minha-url",
type: "post",
data: data,
dataType: "json",
success: function(json) {