Skip to content

Instantly share code, notes, and snippets.

@bockor
bockor / gist:8264a1ae4bf54e2fbc00121dc8dd0e67
Last active March 3, 2021 12:14
infoblox notes // ipam utilization + tls/ssl unsecure messages surpression
import requests
import urllib3
import json
# Surpress SSL/TLS >Insecure Warnings
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
session = requests.Session()
session.auth = ('admin', 'infoblox')
@bockor
bockor / gist:d1a1547b9e37a92f45c2c5fc14b3a096
Created March 3, 2021 11:51
ipython // count number of files per file extension type in directory
from collections import Counter
file_list=!find /home/bruno/tbc/uwsgi/ -type f -name "*"
#print(file_list)
found_ext=[]
for f in file_list:
found_ext.append(f.split('/')[-1].split('.')[-1])
#print(found_ext)
print(Counter(found_ext))
import zipfile
from datetime import datetime
# create zip file name
zip_file_name = 'myzip_{}.zip'.format(datetime.now().strftime("%d%m%Y"))
# create a ZipFile object and compress
zipObj = zipfile.ZipFile(zip_file_name, 'w', zipfile.ZIP_DEFLATED)
# Add multiple files to the zip
@bockor
bockor / gist:190656c3e75fc9716d3d93fd3907bb8b
Last active May 24, 2021 09:07
python difference two dates in years
import datetime
d1_date_str='29/08/1962'
d2_date_str= '06/06/1968'
d1_date_obj=datetime.datetime.strptime(d1_date_str, '%d/%m/%Y')
print(d1_date_obj.date())
d2_date_obj=datetime.datetime.strptime(d2_date_str, '%d/%m/%Y')
print(d2_date_obj.date())
#create datetime.timedelta object
diff = d2_date_obj - d1_date_obj
print(type(diff))
@bockor
bockor / gist:fd1871f97adc9eae3064c96811b19951
Created February 13, 2023 14:33
python sorting ipaddresses
# try to sort ipv4 addr as strings
ss = ['114.122.102.2','114.122.11.1','118.123.12.13','122.14.113.3','192.144.1.5']
print([str(s) for s in sorted(ss)])
# this does not look righ to me ... let's invoke the ipaddress module
from ipaddress import IPv4Address
# and create the ipv4 addr instances
sso = [IPv4Address(s) for s in ss]
#print the sorted ipv4 addr
print([str(s) for s in sorted(sso)])