Skip to content

Instantly share code, notes, and snippets.

View zeph1rus's full-sized avatar
🦖

zeph1rus

🦖
  • United Kingdom
  • 21:51 (UTC +01:00)
View GitHub Profile
@zeph1rus
zeph1rus / uploadFile.fsi
Created July 30, 2023 22:19
Uploading a file async in a form using System.Net.HttpClient in F# and POST requests
let createFileHttpContent (path:string):MultipartFormDataContent =
let file = System.IO.File.OpenRead(path)
let content = new MultipartFormDataContent()
let fileContent = new StreamContent(file)
fileContent.Headers.ContentType <- MediaTypeHeaderValue.Parse("multipart/form-data")
content.Add(fileContent, "file", path)
content
let uploadFile path =
async {
@zeph1rus
zeph1rus / keychainExport.md
Created July 3, 2023 14:51
How to export unexportable items from OSX keychains

How to export non-exportable keychain items (certs/passwords/etc) from the OSX keychain

image

Did you accidentally import keys or passwords into your keychain as unexportable and then lost the originals and really need to grab them.

Well then you need to break the cert out of your keychain - Good News! this is possible, despite what google and stack overflow say!

Note - this all assumes you know your login keychain password - it's a the password you login to OSX with.

@zeph1rus
zeph1rus / octo_decrypt.py
Created May 16, 2022 17:21
Decrypt Octopus Sensitive Variables in Python using the cryptography crypto library and the Master Key
from cryptography.hazmat.primitives.ciphers import (
Cipher, algorithms, modes
)
def octo_decrypt(master_key: str, encrypted_value: str) -> str:
"""
Decrypts Octopus Sensetive values which are encrypted by AES 256 CBC
using the master key from octopus config
:param master_key: Octopus Master Key
@zeph1rus
zeph1rus / return_nothing_if_none.py
Created May 25, 2021 19:35
Python f string none value shows as 'None' in string
def rnn(i: str) -> str:
"""
Python hack. In f-strings, python will interpret '' or "" as "None" instead of, well None, and
thus you get None in text which helps nobody in url strings. This uses an iterator join on a
list comprehension to ensure we return no text at all if the value is none. Thanks python.
:param i: String that may be None or "" or an actual value
:type i: str
:return: the text if it is there else, specifically '' (not None or null like object)
:rtype: str
from werkzeug.datastructures import ImmutableMultiDict
def count_werkzeug_multi_dict(multi_dict: ImmutableMultiDict) -> int:
"""
Counts all of the possible key/value pairs in a multidict, as they have no __len__ implementation, for example
Flask's request.files attribute (in case you want to know how many files got attached to a request
:param multi_dict: A MultiDict object from werkzeug, such as ImmutableMultiDict, should work for it's mutable
version too.
:type multi_dict: ImmutableMultiDict
@zeph1rus
zeph1rus / python regex for netstat parsing
Last active February 18, 2019 16:13
Python Regex for Parsing netstat output
\A\s+(TCP|UDP)\s+([0-9A-Za-z-_.]+):([0-9]+)\s+([0-9A-Za-z-_.]+):([0-9A-Za-z]+)\s+([A-Za-z_-]+)
@zeph1rus
zeph1rus / importjson.py
Last active November 15, 2018 00:35
RabbitMQ (relatively) reliable importer
import json
import http.client
import socket
import base64
import random
def b64(s):
# because erlang.
return base64.b64encode(s.encode('utf-8')).decode('utf-8')
@zeph1rus
zeph1rus / get_disabledoutlookaddins.ps
Last active July 25, 2018 13:52
Search for disabled/slow start outlook addins
$searchScopes = "HKCU:\SOFTWARE\Microsoft\Office\Outlook\Addins","HKLM:\SOFTWARE\Wow6432Node\Microsoft\Office\Outlook\Addins"
$searchScopes | % {Get-ChildItem -Path $_ | % {Get-ItemProperty -Path $_.PSPath} | Select-Object @{n="Name";e={Split-Path $_.PSPath -leaf}},FriendlyName,LoadBehavior} | Where-Object {$_.LoadBehavior -ne 3}