Skip to content

Instantly share code, notes, and snippets.

View alexpdp7's full-sized avatar

Alex Corcoles alexpdp7

  • Barcelona, Spain
View GitHub Profile
@alexpdp7
alexpdp7 / README.md
Last active October 18, 2023 12:53
Ansible Runner lib
>>> import ansible
>>> ansible.run_module("ping", "*").host_results
{'h2.pdp7.net': {'ping': 'pong', 'invocation': {'module_args': {'data': 'pong'}}, 'ansible_facts': {'discovered_interpreter_python': '/usr/bin/python3'}, '_ansible_no_log': None, 'changed': False}, 'h1.pdp7.net': {'ping': 'pong', 'invocation': {'module_args': {'data': 'pong'}}, 'ansible_facts': {'discovered_interpreter_python': '/usr/bin/python3'}, '_ansible_no_log': None, 'changed': False}}
>>> ansible.command("*", "uptime")
{'h1.pdp7.net': CommandResult(host='h1.pdp7.net', stdout=' 14:44:29 up 10 days,  2:59,  1 user,  load average: 0.75, 0.90, 0.72', stderr='', rc=0), 'h2.pdp7.net': CommandResult(host='h2.pdp7.net', stdout=' 14:44:29 up 209 days, 23:39,  1 user,  load average: 0.09, 0.11, 0.12', stderr='', rc=0)}
>>> ansible.command("*", "false")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/acorcole/tmp/20231018-ansiblepy/ansible.py", line 29, in command
@alexpdp7
alexpdp7 / gist:f031e1c4d9908d6d901e9938658c4f8d
Created September 9, 2022 16:35
Scryer parsing experiments
?- [user].
sentence(s(NP,VP)) --> noun_phrase(NP), verb_phrase(VP).
noun_phrase(np(D,N)) --> det(D), noun(N).
verb_phrase(vp(V,NP)) --> verb(V), noun_phrase(NP).
det(d("the")) --> "the".
det(d("a")) --> "a".
noun(n("bat")) --> "bat".
noun(n("cat")) --> "cat".
verb(v("eats")) --> "eats".
^D
@alexpdp7
alexpdp7 / build
Last active February 23, 2022 14:29
Rebuilding rubygem-asciidoctor for EL8
#!/bin/bash
set -ue
mock --clean
function build_gem {
echo ..................................................$1
ls $1-*.el8.src.rpm || {
! test -d $1 && git clone https://src.fedoraproject.org/rpms/$1.git
@alexpdp7
alexpdp7 / AsciiDocParser.java
Created November 4, 2021 14:35
Parsing AsciiDoc using asciidoctor-intellij-plugin
package net.pdp7;
import java.util.Arrays;
import org.asciidoc.intellij.AsciiDocLanguage;
import org.asciidoc.intellij.parser.AsciiDocParserDefinition;
import org.asciidoc.intellij.psi.AsciiDocASTFactory;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonArray;
@alexpdp7
alexpdp7 / Converter.java
Created November 2, 2021 19:32
AsciiDoctor to JSON AST Java Converter hack
import java.io.File;
import java.util.HashMap;
import java.util.Map;
import java.util.stream.Collectors;
import org.asciidoctor.Asciidoctor;
import org.asciidoctor.Options;
import org.asciidoctor.ast.ContentNode;
import org.asciidoctor.ast.Cursor;
import org.asciidoctor.ast.List;
import json
import boto3
# To use, connect to an API gateway, grant route53 permissions and:
#
# curl "https://your_api_gateway_host/prod/updateDdns?host_name=host_name_to_update&secret=matching_secret"
#
# or