Skip to content

Instantly share code, notes, and snippets.

View alexmacniven's full-sized avatar
🍪

Alex Macniven alexmacniven

🍪
View GitHub Profile
@alexmacniven
alexmacniven / main.go
Created June 14, 2022 09:31
Extract a target from a zip archive with Go
package main
import (
"archive/zip"
"io"
"os"
)
func main() {
a := "myArchive.zip"
@alexmacniven
alexmacniven / command-line-openvpn.md
Last active January 4, 2022 10:35
Connecting to and disconnecting from a VPN with OpenVPN and Surfshark configurations

Command Line OpenVPN

This document outlines my findings after hacking with OpenVPN.

Download OpenVPN

I had issues with the latest release of OpenVPN Connect but version 2.5.2 worked fine;

Download Link

Download and install with the default parameters.

@alexmacniven
alexmacniven / flatlist.py
Created June 28, 2021 13:02
Flatten a List with List Comprehension
"""flatlist
Flatten a list of lists using list comprehension.
"""
from typing import List
nest_list: List = [[1, 2, 3], [4, 5, 6]]
flat_list: List = [item for sublist in nest_list for item in sublist]
n = [3, 5, 7]
# This is our function `print_list` which takes `x` as an argument.
# `x` is just a name we give it, it could be anything like... `cat` or `dog`
# In real-world examples you would give your arguments meaningful names like `list_to_print`
def print_list(x):
# Likewise `i` is just a name we've given to a variable
# You could call this `item` or in this case `number`
for i in range(0, len(x)):
# The line above is going to count from 0 to the length of the list we
# https://realpython.com/python-send-email/
# https://stackoverflow.com/a/12424439
import email, smtplib
from email import encoders
from email.mime.base import MIMEBase
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
@alexmacniven
alexmacniven / kwargs-power.md
Created November 18, 2019 16:21
This gist captures the power of Python **kwargs.

Kwargs Power

This code snippet demonstrates how KwargsPower can take any number of **kwargs and it will store them as instance variables.

>>> class KwargsPower:
...   def __init__(self, *args, **kwargs):
...     for k, v in kwargs.items():
...       self.__setattr__(k, v)
      
>>> kp = KwargsPower(a=1, b=2, c=3)
>>> kp.__dict__
@alexmacniven
alexmacniven / unique_string.py
Created October 15, 2019 12:49
Finds unique characters in a string
# Here's the original string.
_string = "abcdde"
# Cast the string into a set of characters.
# Remember sets have all unique elements.
char_set = set(_string)
# Create a string from the character set.
unique_string = "".join(char_set)
class ListComp:
@staticmethod
def diff_a_b(a, b):
"""Returns difference of a and b."""
return list(set(a) - set(b))
@alexmacniven
alexmacniven / logging.ini
Created October 4, 2019 09:18
Standard Logging Config for Python
[loggers]
keys=root
[handlers]
keys=fileHandler
[formatters]
keys=simpleFormatter
[logger_root]