Skip to content

Instantly share code, notes, and snippets.

@jiffyclub
jiffyclub / markdown_doc
Last active August 1, 2023 11:16
This script turns Markdown into HTML using the Python markdown library and wraps the result in a complete HTML document with default Bootstrap styling so that it's immediately printable. Requires the python libraries jinja2, markdown, and mdx_smartypants.
#!/usr/bin/env python
import argparse
import sys
import jinja2
import markdown
TEMPLATE = """<!DOCTYPE html>
<html>
@hreeder
hreeder / parser.py
Last active February 27, 2024 03:53
Python nginx Log Parser
#!/usr/bin/env python
import gzip
import os
import sys
import re
INPUT_DIR = "nginx-logs"
lineformat = re.compile(r"""(?P<ipaddress>\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}) - - \[(?P<dateandtime>\d{2}\/[a-z]{3}\/\d{4}:\d{2}:\d{2}:\d{2} (\+|\-)\d{4})\] ((\"(GET|POST) )(?P<url>.+)(http\/1\.1")) (?P<statuscode>\d{3}) (?P<bytessent>\d+) (["](?P<refferer>(\-)|(.+))["]) (["](?P<useragent>.+)["])""", re.IGNORECASE)
@lxhunter
lxhunter / deploy.sh
Last active August 15, 2019 09:47
Ansible deployment with Travis-CI
#!/bin/bash
[ -z "$GITHUB_SSH_URL" ] && echo "You need to set GITHUB_SSH_URL - e.g. GITHUB_SSH_URL=git@github.com:user/repository.git" && exit 1;
[ -z "$ANSIBLE_PLAYBOOK" ] && echo "You need to set ANSIBLE_PLAYBOOK - e.g. ANSIBLE_PLAYBOOK=deploy.yml" && exit 1;
[ -z "$ANSIBLE_HOSTS" ] && echo "You need to set ANSIBLE_HOSTS - e.g. ANSIBLE_HOSTS=host.ini" && exit 1;
[ -z "$ANSIBLE_ROLES_FOLDER" ] && echo "You need to set ANSIBLE_ROLES_FOLDER - e.g. ANSIBLE_ROLES_FOLDER=/var/tmp/user-repository/roles" && exit 1;
[ -z "$ANSIBLE_REQUIREMENTS_FILE" ] && echo "You need to set ANSIBLE_REQUIREMENTS_FILE - e.g. ANSIBLE_REQUIREMENTS_FILE=/var/tmp/user-repository/requirements.yml" && exit 1;
[ -z "$ANSIBLE_SSH_USER" ] && echo "You need to set ANSIBLE_SSH_USER - e.g. ANSIBLE_SSH_USER=user" && exit 1;
[ -z "$GIT_REPOSITORY" ] && echo "You need to set GIT_REPOSITORY - e.g. GIT_REPOSITORY=/var/tmp/user-repository" && exit 1;
[ -z "$GITHUB_BRANCH" ] && echo "You need to set GITHUB_BRANCH - e.g. GITHUB_BRANCH=master" && exit
@alee
alee / views.py
Last active March 24, 2024 19:00
example Django view function that can be used for Discourse SSO, i.e., Discourse delegates User authentication to Django
import base64
import hmac
import hashlib
from urllib import parse
from django.contrib.auth.decorators import login_required
from django.http import HttpResponseBadRequest, HttpResponseRedirect
from django.conf import settings
@login_required
@Badestrand
Badestrand / react-mini.html
Last active January 28, 2024 12:01
Simple React in browser
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style rel="stylesheet" type="text/less">
* {
margin: 0;
padding: 0;
from typing import Any, Dict, List, Mapping, Union
# Values for JSON that aren't nested
JSON_v = Union[str, int, float, bool, None]
# If MyPy ever permits recursive definitions, just uncomment this:
# JSON = Union[List['JSON'], Mapping[str, 'JSON'], JSON_v]
# Until then, here's a multi-layer way to represent any (reasonable) JSON we
# might send or receive. It terminates at JSON_4, so the maximum depth of