Skip to content

Instantly share code, notes, and snippets.

@mouredev
mouredev / chatgpt_api.py
Created March 7, 2023 19:31
Ejemplo de uso del API de ChatGPT desde Python
import openai # pip install openai
import typer # pip install "typer[all]"
from rich import print # pip install rich
from rich.table import Table
"""
Webs de interés:
- Módulo OpenAI: https://github.com/openai/openai-python
- Documentación API ChatGPT: https://platform.openai.com/docs/api-reference/chat
- Typer: https://typer.tiangolo.com
@bdlangton
bdlangton / Blocks.md
Last active October 12, 2023 08:40
Drupal 8 programmatic solutions

Render custom blocks

$bid = 'myblock';
$block = \Drupal\block_content\Entity\BlockContent::load($bid);
$render = \Drupal::entityTypeManager()->getViewBuilder('block_content')->view($block);

Render plugin blocks

$block_manager = \Drupal::service('plugin.manager.block');
@gjbagrowski
gjbagrowski / ldap_logging.py
Created July 26, 2016 07:34
django-auth-ldap + ldap.forumsys.com
import logging
logger = logging.getLogger('django_auth_ldap')
logger.addHandler(logging.StreamHandler())
logger.setLevel(logging.DEBUG)
@bogvsdev
bogvsdev / image_src.html.twig
Last active May 1, 2020 19:14
Drupal 8 twig, get image url
{% set the_image = item.content['#field_collection_item'].field_featurette_image %}
<img src="{{ file_url(the_image.entity.uri.value) }}" alt="{{ the_image.alt }}" title="{{ the_image.title }}">
or
<img src="{{file_url(node.field_hotel_image.entity.uri.value)}}" alt="3242">