Skip to content

Instantly share code, notes, and snippets.

View klebercode's full-sized avatar
🎯
Focusing

Kleber Soares klebercode

🎯
Focusing
View GitHub Profile
@rochacbruno
rochacbruno / admin.py
Created November 27, 2013 23:29
Django inlines
class PaiFilhosInline(admin.StackedInline):
model = PaiFilhos
fk_name = 'pai'
raw_id_fields = ['filho']
class PaiAdmin(models.ModelAdmin):
inlines = [PaiFilhosInline]
from django.contrib import admin
from .models import Gallery, Image
class ImageInline(admin.StackedInline):
model = Image
extra = 0
fields = ('image',)
@chrillo
chrillo / star.js
Created November 23, 2011 14:07
Draw a star in html canvas
/*
takes the x,y coordinates, the number of spikes, the inner and the outer radius of the spikes
*/
function drawStar(ctx,cx,cy,spikes,r0,r1){
var rot=Math.PI/2*3,x=cx,y=cy,step=Math.PI/spikes
ctx.strokeSyle="#000";
ctx.beginPath();
@derek-schaefer
derek-schaefer / replace.py
Created October 4, 2012 17:05
Django template tag for replacing substrings
from django.template import Library, Node, Variable, \
VariableDoesNotExist, TemplateSyntaxError
register = Library()
def get_var(v, context):
try:
return v.resolve(context)
except VariableDoesNotExist:
return v.var
@lucasmartins
lucasmartins / atualizando_ssl_heroku.md
Last active July 6, 2017 20:45
Gerando um novo cert. SSL e atualizando no Heroku

(check the en_US version here) Gerando um novo cert. SSL e atualizando no Heroku

Para gerar um novo certificado SSL você precisa dos seguintes procedimentos:

  • @dev Gerar um .CSR (é um arquivo texto com uma chave);
  • @dev Enviar o .CSR para a entidade certificadora (TheSSLstore);
    • @dev Verificar o Ownership do domínio via email (também da pra colocar um arquivo no srv. http);
    • @dev Baixar o .CRT (vem um zip com vários .CRT);
  • @dev Criar o bundle.crt
@davidsan
davidsan / instagram.html
Last active October 5, 2017 07:59
Example of JSONP callback on Instagram Search API
<html>
<body>
<button id="btn" type="button">Search for jessicaalba on Instagram using JSONP</button>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/json2/20140204/json2.min.js"></script>
<script src="instagram.js"></script>
</body>
</html>
# Import datetime
from datetime import date
today = datetime.today()
date = date.fromordinal(today.toordinal() - 30) # today - 30 days
object_list = Model.objects.filter(date_at__gte=date)
@vst
vst / todoist.py
Last active March 17, 2018 22:01
A command line tool for Todoist
## Got this script initially from https://gist.github.com/kbl/5970131
###########
# IMPORTS #
###########
import ConfigParser
import argparse
import json
import os
@luzfcb
luzfcb / anp_crawler.py
Last active April 2, 2018 04:15
Implementação simples de um Crawler pra extrair dados do site a ANP
# coding=utf-8
"""
NAO FUNCIONA MAIS. O sistema de CAPTCHA foi trocado.
**Implementa um Webcrawler para extracao de dados da pesquisa de media de precos realizada periodicamente pela ANP**
Desenvolvido por Fabio C. Barrionuevo da Luz. - 2013
Simple crawler to ANP site
Copyright (C) 2013 Fabio C. Barrionuevo da Luz.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
@bragil
bragil / geolocalizacao.py
Created August 25, 2011 18:16
Dado o endereço, obter localização, latitude e longitude
def dados_do_local(endereco):
"""
Dado o endereco, retorna o endereco processado, a latitude e a longitude do local.
Exemplo:
place, (lat, lng) = dados_do_local(endereco)
"""
from geopy import geocoders
if hasattr(settings, "EASY_MAPS_GOOGLE_KEY") and settings.EASY_MAPS_GOOGLE_KEY:
g = geocoders.Google(settings.EASY_MAPS_GOOGLE_KEY)
else: