Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View elinaldosoft's full-sized avatar
🎯
Focusing

Elinaldo Monteiro elinaldosoft

🎯
Focusing
View GitHub Profile
@elinaldosoft
elinaldosoft / cors.conf
Created August 29, 2017 19:38
CORS on Nginx The following Nginx configuration enables CORS, with support for preflight requests.
location ~* ^.+\.(ttf|oft|eot|woff|svg|woff2)$ {
if ($http_origin ~* (https?://[^/]*\.domain.com(:[0-9]+)?)$) {
add_header 'Access-Control-Allow-Origin' "$http_origin" always;
add_header 'Access-Control-Allow-Credentials' 'true' always;
add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS' always;
add_header 'Access-Control-Allow-Headers' 'Accept,Authorization,Cache-Control,Content-Type,DNT,If-Modified-Since,Keep-Alive,Origin,User-Agent,X-Requested-With' always;
}
}
@elinaldosoft
elinaldosoft / settings.py
Last active August 12, 2017 15:35
Enable log of querys in Django!
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'handlers': {
'console': {
'class': 'logging.StreamHandler',
},
},
'loggers': {
'django.db.backends': {
# -*- coding: utf-8 -*-
import logging
logger = logging.getLogger(__name__)
# Define your item pipelines here
#
# Don't forget to add your pipeline to the ITEM_PIPELINES setting
# See: http://doc.scrapy.org/en/latest/topics/item-pipeline.html
class CamaraPipeline(object):
@elinaldosoft
elinaldosoft / override_django_object_seralizer.py
Created July 10, 2017 18:23
Override Django Object Serializer to get rid of specified model
from django.http import JsonResponse
from django.shortcuts import render
from django.core.serializers.python import Serializer
from .models import User
class MySerializer(Serializer):
def get_dump_object(self, obj):
return {
"id": obj._get_pk_val(),
@elinaldosoft
elinaldosoft / git.md
Created July 9, 2017 13:48 — forked from leocomelli/git.md
Lista de comandos úteis do GIT

#GIT

Estados

  • Modificado (modified);
  • Preparado (staged/index)
  • Consolidado (comitted);

Ajuda

[u'cola', u'segment']
{u'size': 5, u'total_messages': 271, u'name': u'segment', u'replicas': 3, u'type': u'pull', u'message_timeout': 60, u'project_id': u'56c27974a8cbf30008000090', u'consistency_factor': u'full_synchronous', u'message_expiration': 604800}
{'timestamp': '2016-03-17T01:54:13.360Z', 'projectId': 'j4bt0Xt7Ie', 'userId': 's.banda', 'integrations': {}, 'receivedAt': '2016-03-17T01:54:13.360Z', 'traits': {'c6_m4_grade': '471', 'c4_m7_viewed_time': '318', 'c5_m2_viewed_time': '366', 'c5_m10_start_time': '427', 'c3_m10_title': '249', 'c1_m2_status': '16', 'c3_m9_grade': '247', 'c3_m4_viewed_time': '206', 'c6_m8_end_time': '500', 'c5_m11_start_time': '435', 'c5_m10_end_time': '428', 'c6_m9_start_time': '507', 'c2_m10_done_time': '165', 'c1_m11_url': '82', 'c4_m11_start_time': '347', 'c5_m3_status': '376', 'c4_m1_title': '265', 'c1_m5_start_time': '35', 'c4_m4_title': '289', 'c4_m1_url': '266', 'c4_m9_viewed_time': '334', 'c5_m1_grade': '359', 'c2_m3_status': '112', 'c2_m2_status': '104', 'c2_m9_grade'
{'timestamp': '2016-03-17T17:53:27.962Z', 'projectId': 'j4bt0Xt7Ie', 'userId': 's.banda', 'integrations': {}, 'receivedAt': '2016-03-17T17:53:27.962Z', 'traits': {'c6_m4_grade': '1170', 'c4_m7_viewed_time': '1017', 'c5_m2_viewed_time': '1065', 'c5_m10_start_time': '1126', 'c3_m10_title': '948', 'c1_m2_status': '715', 'c3_m9_grade': '946', 'c3_m4_viewed_time': '905', 'c6_m8_end_time': '1199', 'c5_m11_start_time': '1134', 'c5_m10_end_time': '1127', 'c6_m9_start_time': '1206', 'c2_m10_done_time': '864', 'c1_m11_url': '781', 'c4_m11_start_time': '1046', 'c5_m3_status': '1075', 'c4_m1_title': '964', 'c1_m5_start_time': '734', 'c4_m4_title': '988', 'c4_m1_url': '965', 'c4_m9_viewed_time': '1033', 'c5_m1_grade': '1058', 'c2_m3_status': '811', 'c2_m2_status': '803', 'c2_m9_grade': '858', 'c4_m6_status': '1011', 'c4_m7_url': '1013', 'c4_m8_start_time': '1022', 'c1_m8_viewed_time': '761', 'c3_m11_end_time': '959', 'c5_m6_end_time': '1095', 'c4_m4_viewed_time': '993', 'c4_m7_grade': '1018', 'c3_m2_viewed_time': '889', '
<!DOCTYPE html>
<html lang=en>
<head>
<meta charset=utf-8>
<meta http-equiv=X-UA-Compatible content="IE=edge">
<meta name=viewport content="width=device-width, initial-scale=1">
<meta name=description content>
<meta name=author content>
<link rel=icon href=favicon.ico>
from fabric.api import env, run, sudo, local, put
def production():
"""Defines production environment"""
env.user = "deploy"
env.hosts = ['example.com',]
env.base_dir = "/var/www"
env.app_name = "app"
env.domain_name = "app.example.com"
env.domain_path = "%(base_dir)s/%(domain_name)s" % { 'base_dir':env.base_dir, 'domain_name':env.domain_name }
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import urllib2,json
def main():
resp = json.loads(urllib2.urlopen("http://divulga.tse.jus.br/2014/divulgacao/oficial/143/dadosdivweb/br/br-0001-e001431-w.js").read())
for cad in resp['cand']:
if (float(cad['v']) / float(resp['vv'])) * 100 > 10:
print "Candidado: %s: votos: %s percentual: %.2f%% de %.1f%% dos votos apurados" % (cad['nm'], cad['v'], (float(cad['v']) / float(resp['vv'])) * 100, (float(resp['ea']) / float(resp['e']) * 100))
if __name__ == '__main__':
main()