Skip to content

Instantly share code, notes, and snippets.

View Ricks-Lab's full-sized avatar

Rick Ricks-Lab

View GitHub Profile
@Ricks-Lab
Ricks-Lab / search_test.py
Last active May 19, 2022 12:10
String Search in a list/tuple/set of Strings
#!/usr/bin/python3
import timeit
import gc
gc.disable()
test_list = ['rick', 'junk', 'fred', 'exclamation point', 'fried', 'rickster', 'john', 'johnathan', 'nathan', 'a', 'b', 'r']
test_set = {'rick', 'junk', 'fred', 'exclamation point', 'fried', 'rickster', 'john', 'johnathan', 'nathan', 'a', 'b', 'r'}
test_tup = ('rick', 'junk', 'fred', 'exclamation point', 'fried', 'rickster', 'john', 'johnathan', 'nathan', 'a', 'b', 'r')
@Ricks-Lab
Ricks-Lab / _pfSenseFirewallAliases.md
Last active March 1, 2022 07:32
IP list text files that can be read by pfSenseNG as Firewall aliases or as IP feeds in pfBlockerNG

pfSense Firewall Alias Files

I noticed that devices (iPhone) on my Taiwan network were using Russian based trackers and ad utilities, so I created a few aliases to be used in the firewall to block all incoming and outgoing traffic to mail.ru and yandex.ru. These files can also be used as feeds for IP blocking in pfBlockerNG.

They can be directly downloaded with these links:

https://gist.githubusercontent.com/Ricks-Lab/0cd738226bdea16237e6765430481bf3/raw/mailru.txt https://gist.githubusercontent.com/Ricks-Lab/0cd738226bdea16237e6765430481bf3/raw/mailruv6.txt

@Ricks-Lab
Ricks-Lab / json_pprint
Created March 26, 2021 06:53
Pretty print a human readable and compliant json object from a dictionary
import pprint
import re
def json_pprint(json_dict: dict) -> None:
""" Print human readable and compliant json file from dict representation of json.
This solution solves the problem of quote differences between dict and json
"""
print(re.sub(r'\'', '\"',
pprint.pformat(json_dict, indent=2, width=120, sort_dicts=False)))
@Ricks-Lab
Ricks-Lab / Flatten List
Last active March 27, 2021 11:17
A function to flatten an arbitrary list of lists, tuples, and other elements using recursion and list comprehension.
#!/usr/bin/python3
""" Demo of recursive list comprehension to flatten arbitrary list of lists and other objects.
"""
from typing import Any
def flatten_list(source: Any) -> list:
""" Flatten arbitrary list of lists or tuples to a simple list of elements. This method works
even if the list contains non-list objects.
"""