Skip to content

Instantly share code, notes, and snippets.

View astrojuanlu's full-sized avatar

Juan Luis Cano Rodríguez astrojuanlu

View GitHub Profile
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@astrojuanlu
astrojuanlu / python3_https_server.py
Last active June 24, 2024 06:21 — forked from stephenbradshaw/python3_https_server.py
Python 3 Simple HTTPS server with Certbot (for Let's Encrypt)
#!/usr/bin/env python3
# Create a basic certificate using Certbot (for Let's Encrypt) and Ansible:
# https://github.com/geerlingguy/ansible-role-certbot
from http.server import HTTPServer, SimpleHTTPRequestHandler
import ssl
domain = "example.com" # Edit with your domain
httpd = HTTPServer(("0.0.0.0", 443), SimpleHTTPRequestHandler)
@astrojuanlu
astrojuanlu / ansible-notes.md
Created November 29, 2022 11:21
Ansible, there we go again
  • To install: pipx install ansible --include-deps
    • If no --include-deps, the actual ansible command, part of ansible-core (a dependency of the ansible metapackage), is not included by pipx
  • Some definitions
    • A host is a remote machine managed by Ansible
    • An inventory is a file that describes a list of managed nodes or hosts that are logically organized in groups
    • A module is a unit of work that Ansible ships to a host
      • Usually written in Python (although more languages are supported)
      • They return a JSON and they are removed from the host after execution
      • For example
  • ansible.builtin.setup is called automatically by playbooks during the implicit "Gather Facts" task
@astrojuanlu
astrojuanlu / async_jsonapi.py
Created April 28, 2022 10:57
Retrieving all paginated results from a JSONAPI using Python, httpx, and asyncio
import asyncio
import os
import httpx
async def get_all(url, headers):
result = {}
next_url = url
@astrojuanlu
astrojuanlu / conda-guide-rtd-notes.md
Last active February 28, 2021 12:40
Notes on writing a conda guide for Read the Docs

Project

a guide on working with conda & RTD. Noting things like how to use conda-forge, and the best practices for using conda and pip together.

The audience

  • Who are they?

Data Scientists, Data Engineers and Developers. Heterogeneous level of programming skills.

@astrojuanlu
astrojuanlu / Walker constellations.ipynb
Last active August 25, 2024 14:14
Analysis of Walker constellations (star pattern) following the 1970 report.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@astrojuanlu
astrojuanlu / rsmooth.py
Created January 4, 2021 11:06
Robust Smoothing of Gridded Data in One and Higher Dimensions with Missing Values
"""Robust smoothing functions.
Translated from Garcia, Damien. 2010. "Robust Smoothing of Gridded Data in One and Higher Dimensions with Missing Values."
Computational Statistics & Data Analysis 54 (4): 1167–78. https://doi.org/10.1016/j.csda.2009.09.020.
"""
import numpy as np
from numpy.linalg import norm
from numpy.matlib import repmat
from scipy.fftpack import dctn, idctn
from __future__ import (absolute_import, division, print_function,
unicode_literals)
import numpy as np
import sys
sys.path.insert(0, '/Users/bmorris/git/tmp/astropy')
import astropy
from astropy.time import Time
from astropy.coordinates import (SkyCoord, Longitude, Latitude, GCRS, ICRS,
@astrojuanlu
astrojuanlu / property_vs_property.txt
Created November 18, 2020 18:37
Comparing @Property access versus direct access
In [1]: class Foo:
...: def __init__(self, a, b):
...: self._a = a
...: self.b = b
...: @property
...: def a(self):
...: return self._a
...:
In [2]: Foo.a
@astrojuanlu
astrojuanlu / aiormq_consumer.py
Last active November 10, 2020 17:44
Asynchronous RabbitMQ/AMQP client using aiormq with graceful cancellation.
import asyncio
import logging
import os
import aiormq
logger = logging.getLogger(__name__)
RABBITMQ_HOST = os.environ["RABBITMQ_HOST"]
RABBITMQ_PORT = os.environ["RABBITMQ_PORT"]