This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
This is a simple Python 3 script to sync all CloudFlare DNS records based on a JSON file. | |
Basically: | |
- It adds new domains if they aren't in CloudFlare yet | |
- For every domain: new DNS records will be added, existing records will be updated and records not existing in the JSON will be deleted | |
By default the script only does a dry run (simulation). Run the script with parameter "execute" to execute it. | |
If you only want to add/update some domains, fill in the "only" key in the JSON file with an array of domains you want to add/update. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Example JSON | |
{ | |
"templates": { | |
"empty": { | |
"records": [] | |
}, | |
"example": { | |
"records": [ | |
{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Input and shared code between parts | |
coords = [tuple(int(c) for c in line.strip().split(',')) for line in open('day6.txt')] | |
xMax = max(coords, key=lambda c: c[0])[0] | |
yMax = max(coords, key=lambda c: c[1])[1] | |
def manhattanDistance(p, q): | |
return abs(p[0] - q[0]) + abs(p[1] - q[1]); | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Input | |
polymer = [unit for unit in ''.join([line.strip() for line in open('day5.txt')])] | |
# Part 1 (+ function also used for part 2) | |
def react(polymer): | |
i = 0 | |
while i + 1 < len(polymer): | |
unit1 = polymer[i] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Prepare and sort data | |
data = [line.strip() for line in open('day4.txt')] | |
data.sort(key=lambda x: x.split(']')[0]) | |
# Part 1 | |
sleepingGuards = {} | |
currentGuard = None | |
asleepFrom = None |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Input for both parts | |
lines = [line.strip() for line in open('day3.txt')] | |
data = [] | |
for line in lines: | |
parts = line.split(' ') | |
id = parts[0] | |
x, y = [int(x) for x in parts[2].rstrip(':').split(',')] | |
w, h = [int(x) for x in parts[3].split('x')] | |
data.append([id, x, y, w, h]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Part 1 | |
from collections import Counter | |
lines = [line.strip() for line in open('day2.txt')] | |
twos = 0 | |
threes = 0 | |
for line in lines: | |
counts = {l: c for l, c in Counter([l for l in line]).items()} | |
twos += 1 if 2 in counts.values() else 0 | |
threes += 1 if 3 in counts.values() else 0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Part 1 | |
print(sum([int(num) for num in open('day1.txt')])) | |
# Part 2 | |
diffs = [int(num) for num in open('day1.txt')] | |
freq = 0 | |
freqs = {} | |
i = 0 |