Skip to content

Instantly share code, notes, and snippets.

@oharsta
oharsta / forms.js
Created November 8, 2024 09:57
Post JS form programmatically
const formPost = (fields, path) => {
const form = document.createElement("form");
form.method = "POST";
form.action = path;
Object.entries(fields).forEach(field => {
const hiddenField = document.createElement("input");
hiddenField.type = "hidden";
hiddenField.name = field[0];
hiddenField.value = field[1];
form.appendChild(hiddenField);
@oharsta
oharsta / FullSearchQueryParser.java
Created December 11, 2024 11:38
MySQL full text indexes autocomplete query parser
public class FullSearchQueryParser {
//SELECT * FROM INFORMATION_SCHEMA.INNODB_FT_DEFAULT_STOPWORD;
private static final List<String> stopWords = List.of(
"a", "about", "an", "are",
"as", "at", "be", "by",
"com", "de", "en", "for",
"from", "how", "i", "in",
"is", "it", "la", "of",
"on", "or", "that", "the",
@oharsta
oharsta / template.py
Created February 12, 2025 10:05
Testing ansible templates in python
from jinja2 import Template
template = Template("""
{% for lang in my_var.split(',') %}
Language: {{ lang }}
{% endfor %}
""")
output = template.render(my_var="en,nl")
print(output)
@oharsta
oharsta / ansible_test.sh
Last active February 12, 2025 10:08
testing ansible templates bash
#!/bin/bash
ansible localhost -m debug -a 'msg={{ "en,nl".split(",") }}'
@oharsta
oharsta / playbook.yml
Created February 12, 2025 10:07
testing ansible playbooks
- hosts: localhost
gather_facts: no
vars:
my_var: "en,nl"
tasks:
- debug:
msg: |
{% for lang in my_var.split(',') %}
Language: {{ lang }}
{% endfor %}