Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env python3.7
class Testing(object):
def __init__(self, a: str, b: str) -> None:
self.a = a
self.b = b
class MyTest(Testing):
@johnsondnz
johnsondnz / python-typing.py
Created October 8, 2019 21:23
Small example on Python Typing
#!/usr/bin/env python3
def testing(a: int, b: int) -> int:
return a + b
print(testing(1,2))
from typing import Dict
from mypy_extensions import TypedDict
@johnsondnz
johnsondnz / add_cloudflare_ips.sh
Created August 24, 2018 06:47 — forked from dduvnjak/add_cloudflare_ips.sh
Add CloudFlare IP addresses to an EC2 Security Group using awscli
# first we download the list of IP ranges from CloudFlare
wget https://www.cloudflare.com/ips-v4
# iterate over the lines in the downloaded file
# make sure to set `--group-id` and `--port`; more details at http://docs.aws.amazon.com/cli/latest/reference/ec2/authorize-security-group-ingress.html
while read p; do aws ec2 authorize-security-group-ingress --group-id sg-e0000000 --protocol tcp --port 80 --cidr $p; done< ips-v4
@johnsondnz
johnsondnz / open-vm-tools-vmware-ubuntu-sharing.md
Created July 18, 2018 01:01 — forked from darrenpmeyer/open-vm-tools-vmware-ubuntu-sharing.md
open-vm-tools and VMWare Shared Folders for Ubuntu guests

(NB: adapted from this Ask Ubuntu thread -- tested to work with Ubuntu 16 LTS branches and Ubuntu 17.10)

Unlike using VMWare Tools to enable Linux guest capabilities, the open-vm-tools package doesn't auto-mount shared VMWare folders. This can be frustrating in various ways, but there's an easy fix.

TL;DR

Install open-vm-tools and run:

sudo mount -t fuse.vmhgfs-fuse .host:/ /mnt/hgfs -o allow_other
@johnsondnz
johnsondnz / nginx.conf
Created November 5, 2017 03:42 — forked from plentz/nginx.conf
Best nginx configuration for improved security(and performance). Complete blog post here http://tautt.com/best-nginx-configuration-for-security/
# to generate your dhparam.pem file, run in the terminal
openssl dhparam -out /etc/nginx/ssl/dhparam.pem 2048
@johnsondnz
johnsondnz / dict.py
Created September 12, 2017 00:50
Check it an ansible element is a dictionary, handy for defining an object with no iterables
from ansible import errors
from jinja2.filters import environmentfilter
class FilterModule(object):
def filters(self):
return {
'dict': self.dict
}
def dict(*args):
if isinstance(args[1], dict):
@johnsondnz
johnsondnz / iterable.py
Last active September 6, 2017 23:57 — forked from udondan/iterable.py
Ansible filter plugin for testing if variables are a list
from ansible import errors
from jinja2.filters import environmentfilter
class FilterModule(object):
def filters(self):
return {
'iterable': self.iterable
}
def iterable(*args):
if isinstance(args[1], list):
@johnsondnz
johnsondnz / testing.txt
Last active July 25, 2017 23:38
Ansible Junos JSON variables
I am running ver 2.3
ubuntu@ansible-jsnapy:~$ ansible --version
ansible 2.3.1.0
config file =
configured module search path = Default w/o overrides
python version = 2.7.12 (default, Nov 19 2016, 06:48:10) [GCC 5.4.0 20160609]
I found this pull request which looks like it would resolve this issue.
https://github.com/ansible/ansible/pull/26382
@johnsondnz
johnsondnz / orion.py
Last active March 12, 2024 06:29
Orion SDK - Python Class
# orionsdk
# https://github.com/solarwinds/orionsdk-python
from orionsdk import SwisClient
import re
import datetime
import requests
class Orion():