Skip to content

Instantly share code, notes, and snippets.

@gfody
gfody / JsonToXml.cs
Last active July 31, 2024 19:27
converts json string to XmlElement, no System.Runtime.Serialization dependency
XmlElement JsonToXml(string json, string root = "root", string unnamed_array_item = "item")
{
var r = new Regex(@"\s*([\[\]{}]|""([^""]*)""\s*:|(true|false|null|-?\d+(?:\.\d+)?|""[^""]*"")\s*),?", RegexOptions.Multiline | RegexOptions.Compiled);
var doc = new XmlDocument(); var n = doc.CreateElement(root); var s = new Stack<XmlElement>(); string name = null, value = "";
var m = r.Match(json);
while (m.Success)
{
if (m.Groups[1].Value == "]") name = null;
else if (m.Groups[1].Value == "[") name = name ?? unnamed_array_item;
else if (m.Groups[1].Value.EndsWith(":")) name = m.Groups[2].Value;
@sherzodinaev
sherzodinaev / set-hostname-windows-ssm.yaml
Created February 23, 2018 01:47
Set Windows hostname via SSM
---
schemaVersion: '2.2'
description: Sets computer name for computer(s) that is(are) part of the domain, using the value of Name tag for the selected resource(s).
mainSteps:
- action: aws:runPowerShellScript
name: setComputerNameFromTag
precondition:
StringEquals:
- platformType
- Windows
@ajorg
ajorg / ad-nsupdate.sh
Last active October 6, 2024 17:48
Update Active Directory DNS host records using machine / host / computer credentials and nsupdate
#!/bin/bash -e
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: MIT-0
fqdn="$(hostname -f)"
address="$(/sbin/ip addr show dev eth1 | awk -F'( +|/)' '/inet / {print $3}')"
if [[ "${address}" == "$(dig +short "${fqdn}")" && "${fqdn}." == "$(dig +short -x "${address}")" ]]
then
exit 0
fi
TTL=21600 # 6 hours