Skip to content

Instantly share code, notes, and snippets.

@augustogoulart
augustogoulart / hellofy.py
Created July 25, 2017 00:52
Simple example of how to use a @Property decorator
""""
Simple example of how to use a @property decorator
"""
class Hellofy:
def __init__(self, name, message):
self.name = name
self.message = message
@augustogoulart
augustogoulart / fstrings_performance.py
Last active July 22, 2017 15:56
Comparing f-string performance versus .format()
import timeit
def test_fstring():
for string in range(1000):
f'{string}'
def test_format():
for string in range(1000):
@augustogoulart
augustogoulart / dogs_only.py
Created July 21, 2017 21:10
Exemple of exceptions and type validation
"""
Exemple of exceptions and type validation
"""
class Dog:
def __init__(self, name):
self.name = name
@augustogoulart
augustogoulart / duck_typing.py
Created July 21, 2017 17:56
Example of Pythons duck typing
"""
Example do demonstrate Python's Duck Typing
In [1]: from collections import Container
In [2]: Container.__abstractmethods__
Out[3]: frozenset({'__contains__'})
"""
@augustogoulart
augustogoulart / LongNameDict.py
Created July 20, 2017 20:03
Extending Python's dictionary
class LongNameDict(dict):
def longest_value(self):
longest = None
for key, value in self.items():
if not longest or len(value) > len(longest):
longest = value
return longest
names = LongNameDict(first='josé', second='schwarzenegger')
@augustogoulart
augustogoulart / PowerList.py
Last active July 20, 2017 20:02
Extending python built-ins
"""
Simple example to explain how to extend built-in python objects
"""
class PowerList(list):
def search(self, name):
results = []
for obj in self:
if obj == name:
results.append(name)
return results
@augustogoulart
augustogoulart / bashrc.sh
Created June 27, 2017 16:23
Example of some django aliases
alias manage='python $(cat $(echo $VIRTUAL_ENV/.project))/manage.py'
alias test='python $(cat $(echo $VIRTUAL_ENV/.project))/manage.py test'
alias runserver='python $(cat $(echo $VIRTUAL_ENV/.project))/manage.py runserver'
alias makemigrations='python $(cat $(echo $VIRTUAL_ENV/.project))/manage.py makemigrations'
alias migrate='python $(cat $(echo $VIRTUAL_ENV/.project))/manage.py migrate'
alias shell='python $(cat $(echo $VIRTUAL_ENV/.project))/manage.py shell'
alias shellp='python $(cat $(echo $VIRTUAL_ENV/.project))/manage.py shell_plus'
@augustogoulart
augustogoulart / urlquest.py
Created June 16, 2017 14:26
Explorando a flexibildade das urls do Django.
import os
from django.conf.urls import url, include
from django.urls import set_urlconf, resolve, reverse
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'eventex.settings')
def index(request): pass
def auth(request): pass
@augustogoulart
augustogoulart / gist:7676b82b3168e65ee0d4b807b94052e6
Created June 14, 2017 20:05
Creates a visual representations of the database
manage graph_models subscriptions | dot -Tpng -o test.png
@augustogoulart
augustogoulart / .js
Created June 1, 2017 20:22
Ajax call to meetup API
$('.btn').click(function () {
$('.text').text('loading...');
$.ajax({
type:"GET",
url:"https://api.meetup.com/2/cities",
success: function (data) {
$('.text').html('');
for(var i=0;i < data.results.length;i++){
var place = data.results[i].city
$('.text').append('<p>'+place+'</p>');