Skip to content

Instantly share code, notes, and snippets.

View rsperl's full-sized avatar

Richard rsperl

  • North Carolina, United States
View GitHub Profile
@rsperl
rsperl / generate_iterm2_dynamic_profiles.pl
Last active July 25, 2022 13:08
Reads in ~/.ssh/config and generates iterm2 dynamic profiles #perl #iterm2 #macos #ssh #snippet
#!/usr/bin/env perl
#
# licensed under GPL v2, same as iTerm2 https://www.iterm2.com/license.txt
#
use strict;
use JSON;
my $output = $ENV{HOME} . "/Library/Application\ Support/iTerm2/DynamicProfiles/profiles.json";
@rsperl
rsperl / ldap.py
Last active July 25, 2022 13:18
connect to ldap #python #ldap #snippet
#!/usr/bin/env python
import ldap
import sys
def get_connection(uri, username, password):
# or set env var LDAPTLS_REQCERT=never
ldap.set_option(ldap.OPT_X_TLS_REQUIRE_CERT, ldap.OPT_X_TLS_ALLOW)
@rsperl
rsperl / backup_with_timestamp.py
Last active July 25, 2022 13:19
backup a file with a timestamp #python #snippet
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from datetime import datetime
import shutil
origfile = "myfile.txt"
backupfile = origfile + "." + datetime.now().strftime("%Y-%m-%d_%H%M%S")
shutil.copy(origfile, backupfile)
@rsperl
rsperl / convert_ldap_objectguid.py
Last active July 25, 2022 13:20
convert ldap object guid to hex string and back #python #ldap #snippet
# source: http://stackoverflow.com/questions/25299971/python-ldap-converting-objectguid-to-hex-string-and-back
def guid2hexstring(val):
s = ['\\%02X' % ord(x) for x in val]
return ''.join(s)
guid = ldapobject.get('objectGUID', [''])[0] # 'Igr\xafb\x19ME\xb2P9c\xfb\xa0\xe2w'
guid2string(guid).replace("\\", "") # '496772AF62194D45B2503963FBA0E277'
#and back to a value you can use in an ldap search filter
@rsperl
rsperl / ip_generator.py
Last active July 25, 2022 13:23
Example generator to list IP addresses #python #networking #snippet
#!/usr/bin/env python
class IpGenerator(object):
# pass in the list of things to iterate over
def __init__(self, ips):
self.ips = ips
def __iter__(self):
@rsperl
rsperl / install_python-ldap.sh
Last active July 25, 2022 16:07
fix sasl.h is required error #python #ldap #snippet
# when you get the error "sasl.h is required"
xcrun --show-sdk-path
sudo ln -s <the_path_from_above_command>/usr/include /usr/include
# if you get "Operation not permitted," you probably need to disable SIP:
# reboot, hold down cmd-R, choose Utilities -> Terminal, type "csrutil disable,"
# reboot, try the steps above again
pip install python-ldap
@rsperl
rsperl / jinja2_example.py
Last active July 25, 2022 13:24
Using Jinja2 in a script #python #jinja2 #snippet
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import jinja2
scriptdir = os.path.dirname(os.path.realpath(__file__))
tmpl = scriptdir + "/mytemplate.j2"
dest = scriptdir + "/outputfile.txt"
@rsperl
rsperl / formatted_timestamp.sql
Last active August 4, 2021 20:02
formatted timestamp #mysql #dates
select TIME_FORMAT(SEC_TO_TIME(endtime - runtime),'%Hh %im');
@rsperl
rsperl / openssl_commands.md
Last active July 25, 2022 13:52
openssl commands #snippet

Most Common OpenSSL Commands

Source: https://www.sslshopper.com/article-most-common-openssl-commands.html

General OpenSSL Commands

These commands allow you to generate CSRs, Certificates, Private Keys and do other miscellaneous tasks.

# Generate a new private key and Certificate Signing Request
openssl req -out CSR.csr -new -newkey rsa:2048 -nodes -keyout privateKey.key
@rsperl
rsperl / create_filesystems.sh
Last active July 25, 2022 14:47
create an LVM-managed filesystems and use systemd to mount it #snippet
#!/bin/sh
pvcreate /dev/vdb
vgcreate vgdocker /dev/vdb
lvcreate -l 100%VG -n lvdocker vgdocker
mkfs -t xfs /dev/vgdocker/lvdocker
mkdir /tmp/d
mount /dev/vgdocker/lvdocker /tmp/d
umoun /tmp/d
mount /dev/vgdocker/lvdocker /var/lib/docker