Skip to content

Instantly share code, notes, and snippets.

View DDuarte's full-sized avatar
😴
Dormant

Duarte Duarte DDuarte

😴
Dormant
View GitHub Profile
import yaml
import json
import sys
with open(sys.argv[1]) as f:
y = yaml.safe_load(f)
with open(sys.argv[1].replace("yml", "json").replace("yaml", "json"), "w") as ff:
json.dump(y, ff)
@DDuarte
DDuarte / ciphers.py
Created January 19, 2022 15:44
TLS clients that do not support certain ciphers
# https://www.ssllabs.com/ssltest/clients.html
import requests
SUPPORTED_CIPHERS = {
"TLS_AES_128_GCM_SHA256",
"TLS_AES_256_GCM_SHA384",
"TLS_CHACHA20_POLY1305_SHA256",
"TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256",
"OLD_TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256",
@DDuarte
DDuarte / public_subnets.py
Created April 9, 2021 16:19
IPv4 public subnets excluding RFC 1918
from ipaddress import ip_network
rfc_1918 = [ip_network('10.0.0.0/8'), ip_network('172.16.0.0/12'), ip_network('192.168.0.0/16')]
final = [ip_network('0.0.0.0/0')]
for ex in rfc_1918:
for n in list(final):
try:
final.extend(n.address_exclude(ex))
final.remove(n)
@DDuarte
DDuarte / cloudflare_request_stats.py
Created December 15, 2020 16:38
Get HTTP request statistics for all zones in a Cloudflare account
import csv
import os
import requests
EMAIL = os.getenv("CLOUDFLARE_EMAIL")
API_KEY = os.getenv("CLOUDFLARE_API_KEY")
ACCOUNT_ID = os.getenv("CLOUDFLARE_ACCOUNT_ID")
s = requests.Session()
@DDuarte
DDuarte / shrink.py
Created August 20, 2020 17:12
Shrink existing ElasticSearch indexes, keep index name (using aliases)
import argparse
import logging
import typing as t
from elasticsearch import Elasticsearch # type: ignore
from tqdm.auto import tqdm # type: ignore
JSON = t.Union[str, int, float, bool, None, t.Dict[str, t.Any], t.List[t.Any]]
# not performant, not useful for large lists
# cake(a: List[int]) -> int:
cake=lambda a,l=len,g=range:max([l(r)for r in[a[i:j+1]for i in g(l(a))for j in g(i,l(a))]if sum(r)==l(r)/2]+[0]) # 112
def test_1():
assert cake([]) == 0
def test_2():
import re as e
import sys as y
from collections import defaultdict as d
o,r=sorted,d(set)
[r["".join(o(w))].add(w)for w in e.split("\W"," ".join(y.stdin).lower())if len(w)==int(y.argv[1])]
[print(w+": "+",".join(o(r[w])))for w in o(r)]
/**
* @param {string} alphabet
* @param {string} key
* @param {string} text
* @return {string}
*/
f = (
@DDuarte
DDuarte / create_files.py
Last active March 12, 2017 15:34
Generate WPP message files
import re
curr_file = None
with open('structs_601_18179.cs', 'r') as s:
for line in s:
if line.startswith('}'):
curr_file.write(' ' + line + '}\n')
curr_file.close()
curr_file = None
@DDuarte
DDuarte / spellwork_appveyor.yml
Created January 21, 2017 21:23
AppVeyor YML configs 21 Jan 2017
version: 1.0.{build}
configuration:
- Debug
- Release
platform: Any CPU
before_build:
- cmd: nuget restore
build:
verbosity: minimal
artifacts: