Skip to content

Instantly share code, notes, and snippets.

@mvanderlee
mvanderlee / demo.py
Last active June 14, 2023 14:56
Paramiko's interactive demo with support for control characters in posix.
import contextlib
import questionary
import os
from interactive_ssh import interactive_shell
class ConfirmAddPolicy(paramiko.client.MissingHostKeyPolicy):
"""
Policy for confirming the user if they want to add the hostname and new host key to the
@mvanderlee
mvanderlee / quart_parser.py
Created January 21, 2021 05:01
Quart webargs parser
# -*- coding: utf-8 -*-
"""Quart request argument parsing module.
Example: ::
from quart import Quart
from webargs import fields
from webargs.quartparser import use_args
@mvanderlee
mvanderlee / aws_mfa.py
Last active May 7, 2020 18:06
AWS CLI utilities
'''
Configures AWS CLI config with the MFA session token.
Recommended usage:
* Set 'MFA_ARN' env variable
* Run `python aws_mfa.py`. Script will prompt you for the mfa code.
'''
import boto3
import click
@mvanderlee
mvanderlee / access_rules.yml
Last active April 7, 2020 00:40
Ory Oathkeeper Integration with Traefik
---
- id: rule1
match:
url: <.*>/api/auth/users
methods: ["GET"]
authenticators:
- handler: noop
authorizer:
handler: allow
mutators:
@mvanderlee
mvanderlee / ng-add-pug-loader.js
Created October 30, 2018 04:52
ng-add-pug-loader with pug-plugin-ng
/**
* Adds the pug-loader inside Angular CLI's webpack config, if not there yet.
* @see https://github.com/danguilherme/ng-cli-pug-loader
*/
const fs = require('fs');
const commonCliConfig = 'node_modules/@angular-devkit/build-angular/src/angular-cli-files/models/webpack-configs/common.js';
const pugImport = 'const PugNgPlugin = require("pug-plugin-ng");';
const pugRule = '{ test: /.pug$/, use: [ { loader: "html-loader" }, { loader: "pug-html-loader", options: {doctype: "html", plugins: PugNgPlugin} } ] },';
fs.readFile(commonCliConfig, (err, data) => {
@mvanderlee
mvanderlee / ip_helpers.py
Created February 28, 2018 01:00
IPv4 helper methods.
def uint(i):
return 0xffffffff & i
def IP2Int(ip):
o = map(int, ip.split('.'))
res = (16777216 * o[0]) + (65536 * o[1]) + (256 * o[2]) + o[3]
return res
def Int2IP(ipnum):