Skip to content

Instantly share code, notes, and snippets.

View douglasmiranda's full-sized avatar
👽

Douglas Miranda douglasmiranda

👽
  • Earth, Brazil
View GitHub Profile
@michiel
michiel / cors-nginx.conf
Created July 5, 2011 10:41
Wide-open CORS config for nginx
#
# Wide-open CORS config for nginx
#
location / {
if ($request_method = 'OPTIONS') {
add_header 'Access-Control-Allow-Origin' '*';
#
@andrewsmedina
andrewsmedina / gist:1154225
Created August 18, 2011 14:54
python *args, **kwargs
>>> def teste(nome, idade):
... print nome, idade
...
>>> teste('andrews', 26)
andrews 26
>>> teste(nome='andrews', idade=26)
andrews 26
>>> lista = ['pacote', 200]
>>> teste(*lista)
pacote 200
@douglasmiranda
douglasmiranda / 1ntro.markdown
Last active January 13, 2020 03:28
Django + git + apache mod_wsgi na Kinghost

#Django + git + apache mod_wsgi na Kinghost

NOTE: Atualmente não é necessário tanto para fazer deploy de aplicações Django na Kinghost.

I hope you like it!

##Início

Talvez você não queira ficar digitando a senha toda vez que usar o ssh, então adicione sua chave pública ao seu host:

@andrewsmedina
andrewsmedina / Makefile
Created December 5, 2011 01:03 — forked from turicas/Makefile
Create slugs using Python
test:
clear
nosetests --with-coverage --cover-package slugfy test_slugfy.py
clean:
find -regex '.*\.pyc' -exec rm {} \;
find -regex '.*~' -exec rm {} \;
.PHONY: test clean
@flavianmissi
flavianmissi / json_response_generic_view.py
Created December 13, 2011 17:57
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)
return HttpResponse(json_data, content_type="application/json", **httpresponse_kwargs)
@bostwick
bostwick / FacebookWordCloud.py
Created February 11, 2012 04:00
Facebook News Feed Word Cloud
#!/usr/bin/env python
import sys
import urllib2
import json
from collections import defaultdict
from nltk import word_tokenize
IGNORED_WORDS = ["!", ".", ",", "(", ")", "'s", ":", "?", "...", "$",
@maraujop
maraujop / forms.py
Created February 15, 2012 19:04
django-crispy-forms bootstrap form example
# -*- coding: utf-8 -*-
from django import forms
from crispy_forms.helper import FormHelper
from crispy_forms.layout import Layout, Div, Submit, HTML, Button, Row, Field
from crispy_forms.bootstrap import AppendedText, PrependedText, FormActions
class MessageForm(forms.Form):
text_input = forms.CharField()
@hrldcpr
hrldcpr / tree.md
Last active May 1, 2024 00:11
one-line tree in python

One-line Tree in Python

Using Python's built-in defaultdict we can easily define a tree data structure:

def tree(): return defaultdict(tree)

That's it!

@gilsondev
gilsondev / views.py
Created May 25, 2012 19:29
Using reverse function with Class based generic view in success_url
# -*- coding: utf8 -*-
from django.views.generic.edit import FormView
from django.core.urlresolvers import reverse
class FooFormView(FormView):
template_name = 'foo/foo_form.html'
form_class = FooForm
@alyssonbruno
alyssonbruno / clone.py
Last active May 6, 2023 23:03
Make a clone of one file or device. Emule the command dd, without type conversion
import io
import mmap
from typing import Optional
_DEFAULTBS=io.DEFAULT_BUFFER_SIZE
def clone(input_file: Optional[str]='/dev/zero', output_file: Optional[str]='/dev/null', block_size: Optional[int]=_DEFAULTBS, count: Optional[int]=None, verbose: Optional[bool]=False):
"""Make a clone of one file or device. Emule the command dd, without type conversion
>>> clone(output_file='/tmp/swap.img',bs=512,count=8*2*1024*1024*1024)