Skip to content

Instantly share code, notes, and snippets.

@gfody
gfody / JsonToXml.cs
Last active July 19, 2019 17:29
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;
@cveld
cveld / Crawl_Android.ps1
Last active June 23, 2024 20:19
PowerShell that crawls your Android usb folder structure
# http://blogs.technet.com/b/heyscriptingguy/archive/2013/04/26/use-powershell-to-work-with-windows-explorer.aspx
$o = New-Object -com Shell.Application
$folder = $o.NameSpace(0x11)
# https://msdn.microsoft.com/en-us/library/windows/desktop/bb774096(v=vs.85).aspx
# ShellSpecialFolderConstants.ssfDRIVES == 0x11
$items = $folder.Items()
for ($i= 0; $i -lt $items.Count; $i++) {
write-output ([string]$i + ": " + $items.Item($i).Name)
@smoothdeveloper
smoothdeveloper / generate_add_and_drop_all_constraints.sql
Created February 27, 2015 13:22
SqlServer: Generate alter add / drop for all type of constraints (foreign key, unique and check)
with
unique_constraint_infos (schemaname, tablename, constraintname, columnname)
as (
select
quotename(tc.table_schema)
, quotename(tc.table_name)
, quotename(tc.constraint_name)
, quotename(cc.column_name)
from
information_schema.table_constraints tc
@shawndumas
shawndumas / .gitconfig
Created August 5, 2013 19:08
Using WinMerge as the git Diff/Merge Tool on Windows 64bit
[mergetool]
prompt = false
keepBackup = false
keepTemporaries = false
[merge]
tool = winmerge
[mergetool "winmerge"]
name = WinMerge