Skip to content

Instantly share code, notes, and snippets.

View kamon's full-sized avatar
🎯
Learning more on these APIs: Icinga2, Jira, Twilio

Kamon Ayeva kamon

🎯
Learning more on these APIs: Icinga2, Jira, Twilio
View GitHub Profile
@kamon
kamon / request-example-get.py
Created October 30, 2025 17:40
GET request example (OpenAI API)
import requests
api_key = "sk-..."
resp = requests.get("https://api.openai.com/v1/models", headers={"Authorization": f"Bearer {api_key}"})
print(resp.json())
@kamon
kamon / cache-requests.py
Last active October 30, 2025 12:59
Cache HTTP requests using requests-cache
# pip install requests requests-cache
import requests
import requests_cache
from datetime import timedelta
# Enable a transparent on-disk HTTP cache (GET only)
requests_cache.install_cache(
cache_name=".http_cache", # folder/files on disk
expire_after=timedelta(hours=6), # global TTL
allowable_methods=("GET",), # don't cache POST/PUT by default
@kamon
kamon / free_reader.py
Created February 28, 2018 17:32 — forked from berinhard/free_reader.py
Um leitor gratuito para jornais
import requests
import sys
import textwrap
from lxml.html import document_fromstring
from optparse import OptionParser
from urllib.parse import urlparse
class FolhaSpParser(object):
@kamon
kamon / manipulate-dicts.py
Created February 28, 2018 15:09
Python examples - Illustrate how we use the Dictionary type
# Inspired by https://en.wikibooks.org/wiki/Cookbook and others.
cookbook = {
'risotto': {'name': 'Risotto', 'category': 'Rice recipes', 'url': 'https://en.wikibooks.org/wiki/Cookbook:Risotto',},
'crepe': {'name': 'Crêpe', 'category': 'Breakfast recipes', 'url': 'https://en.wikibooks.org/wiki/Cookbook:Cr%C3%AApe',},
'bouillabaisse': {'name': 'Bouillabaisse', 'category': 'French recipes', 'url': 'https://en.wikibooks.org/wiki/Cookbook:Bouillabaisse',},
}
# Iterate by key
@kamon
kamon / generate-fake-data.py
Last active February 28, 2018 13:18
Python examples - Generate fake data using the faker library
# Requires the installation of "faker": pip install faker
from faker import Faker
fake = Faker()
for _ in range(0, 20):
p = {'firstname': fake.last_name(), 'lastname': fake.last_name()}
print(p)
@kamon
kamon / sort-collections.py
Last active February 28, 2018 13:17
Python examples - Sort collections
# We use the standard module "operator"
import operator
# A dictionary
C = {4:'abc', 2:'gfc', 5:'afe', 3:'fgh'}
# Sort by the dictionary keys ; produces a list of the items tuples.
C1 = sorted(C.items(), key=operator.itemgetter(0))
print(C1)
@kamon
kamon / views.py
Created October 9, 2014 11:21
Examples of Plone browser view classes for managing users and groups
from Products.Five.browser import BrowserView
from plone import api
class CustomRegisterUserView(BrowserView):
"""View to create a new user 'jdoe'.
"""
def __call__(self):
@kamon
kamon / Document.xml
Created February 27, 2014 12:59
Override of plone.app.contenttypes' profiles/default/types/Document.xml to set all behaviors I want on the Document type
<?xml version="1.0"?>
<object name="Document" meta_type="Dexterity FTI" i18n:domain="plone"
xmlns:i18n="http://xml.zope.org/namespaces/i18n">
<property name="title" i18n:translate="">Page</property>
<property name="behaviors">
<element value="plone.app.content.interfaces.INameFromTitle"/>
<element value="plone.app.dexterity.behaviors.discussion.IAllowDiscussion"/>
<element value="plone.app.dexterity.behaviors.exclfromnav.IExcludeFromNavigation"/>
<element value="plone.app.dexterity.behaviors.metadata.IDublinCore"/>