Skip to content

Instantly share code, notes, and snippets.

View neilmcguigan's full-sized avatar

Neil McGuigan neilmcguigan

  • Vancouver, Canada
  • 20:30 (UTC -08:00)
View GitHub Profile
testing:
https://grokdebugger.com/
https://grokconstructor.appspot.com/do/match#result
log samples:
https://www.ossec.net/docs/log_samples/databases/postgresql.html
grok examples:
@neilmcguigan
neilmcguigan / cloudformation-foreach.yaml
Last active April 19, 2024 02:19
cloudformation foreach loops
# the key is to use &{foo} for resource identifiers, to strip out bad chars
Transform: AWS::LanguageExtensions
Parameters:
BucketNames:
Type: CommaDelimitedList
Resources:
@neilmcguigan
neilmcguigan / xidel.sh
Created April 16, 2024 03:38
xidel scraping
# get the current url (watch your quoting):
xidel https://example.com --extract '$url'
# output JSON lines:
xidel --printed-json-format=compact https://example.com --extract '{"title"://title, "url": $url}'
# for a list of items, with pagination: follow item, extract data, paginate:
1. Jinja Macros can return results (but only if `called`):
```
{% macro foo() %}
hello from foo
{{ caller({"bar":1}) if caller is defined }}
{% endmacro %}
{% call(result) foo() %}
{{result.bar}}
@neilmcguigan
neilmcguigan / optimistic-locking.py
Created April 1, 2023 23:16
A sample app to show how to use optimistic concurrency / optimistic locking in Flask and SQLAlchemy
"""
A sample app to show how to use optimistic concurrency / optimistic locking in Flask and SQLAlchemy
The trick is to store your entity in session between requests
You need to use Flask-Session, so can serialize your entities properly
Usage:
flask --app optimistic-locking.py run
navigate to http://127.0.0.1:5000/edit/1
@neilmcguigan
neilmcguigan / fastapi-htmx
Last active March 8, 2023 23:03
FastAPI HTMX
# main.py
@app.middleware("http")
async def set_xhr(request: Request, call_next):
request.state.is_xhr = "HX-Request" in request.headers
return await call_next(request)
# in your Jinja2 template :
{% if request.state.is_xhr %}
# TAG is a Redshift keyword, so we have to create this table ourselves, and quote TAG
# otherwise, you need a custom database class for liquibase
# see https://github.com/liquibase/liquibase-redshift
CREATE TABLE public.databasechangelog (
ID VARCHAR(255) NOT NULL,
AUTHOR VARCHAR(255) NOT NULL,
FILENAME VARCHAR(255) NOT NULL,
DATEEXECUTED TIMESTAMP WITHOUT TIME ZONE NOT NULL,
ORDEREXECUTED INTEGER NOT NULL,