Skip to content

Instantly share code, notes, and snippets.

View arthuralvim's full-sized avatar

Arthur Alvim arthuralvim

View GitHub Profile
@jerivas
jerivas / active_user_middleware.py
Last active August 29, 2015 13:56
[Django] Active User Middleware. Let's you blacklist URLs requiring user auth without decorating every view. Whitelist approach here: https://djangosnippets.org/snippets/2845/
from re import compile
from django.conf import settings
from django.contrib.auth import REDIRECT_FIELD_NAME
from django.contrib.auth.views import redirect_to_login
if hasattr(settings, "LOGIN_REQUIRED_URLS"):
URLS = [compile(expr) for expr in settings.LOGIN_REQUIRED_URLS]
@gdugas
gdugas / progressbar.js
Created March 17, 2014 13:48
BackboneJs Progressbar
var ProgressItem = Backbone.Model.extend({
defaults: {
max: 100,
value: 0
},
getValueRatio: function () {
return this.get('value') * 100 / this.get('max');
}
@dz1984
dz1984 / Vagrantfile
Created March 23, 2014 01:29
My default vagrant setting.
# -*- mode: ruby -*-
# vi: set ft=ruby :
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "precise64"
config.vm.box_url = "http://files.vagrantup.com/precise64.box"
config.vm.network :forwarded_port, guest: 80, host: 8080
from django.views.generic import TemplateView
if settings.DEBUG:
# enable local preview of error pages
urlpatterns += patterns('',
(r'^403/$', TemplateView.as_view(template_name="403.html")),
(r'^404/$', TemplateView.as_view(template_name="404.html")),
(r'^500/$', TemplateView.as_view(template_name="500.html")),
@willmendesneto
willmendesneto / Gruntfile.js
Last active August 29, 2015 14:01
Files requireds for create a project for create angular modules using Grunt task manager
'use strict';
// # Globbing
// for performance reasons we're only matching one level down:
// 'test/spec/{,*/}*.js'
// use this if you want to recursively match all subfolders:
// 'test/spec/**/*.js'
// OBS:
// Replace the string with informations
@sebdah
sebdah / forms.py
Created June 24, 2014 13:25
Handling unique_together errors in Django forms
class MyModelForm(ModelForm):
class Meta:
model = MyModel
fields = ('field2', 'field3', 'field4', 'field5')
def clean(self):
"""
Clean MyModel
"""
# Get the cleaned data
# simples fabfile para aplicar o patch para o bug CVE-2014-6271
__author__ = 'juliomelo'
from fabric.api import *
from fabric.decorators import hosts
import re
env.use_ssh_config=True
@hosts('host_foo', 'host_bar')
@task
@fmasanori
fmasanori / Copa2014.py
Last active August 29, 2015 14:23
Gastos da Copa 2014
#The context of this program is a course of an hour to journalists who know nothing about programming in a lab with Python 3 only.
import urllib.request
url = 'http://www.portaltransparencia.gov.br/copa2014/api/rest/empreendimento'
resp = urllib.request.urlopen(url).read().decode('utf-8')
total = 0
j = 0
and1 = '<andamento>'
and2 = '</andamento>'
abre = '<valorTotalPrevisto>'
fecha = '</valorTotalPrevisto>'
@mxriverlynn
mxriverlynn / 1.js
Created February 3, 2012 18:37
stages of backbone app startup
App = {
init: function(){
// app initialization and startup goes here
}
}
App.init();
@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) {