Skip to content

Instantly share code, notes, and snippets.

@dgroft
dgroft / xml_transform_and_validate.py
Created November 22, 2013 15:17
Applies XSL transform to XML returned from an HTTP request, then validates it against an XSD/schema.
from __future__ import print_function
import argparse
import lxml.etree as ET
import urllib
parser = argparse.ArgumentParser(description="Transforms and Validates XML")
parser.add_argument("--feeds", help="the text file that holds the urls to be validated", default="feeds.txt")
parser.add_argument("--log", help="the output log file that reports all errors", default="log.txt")
parser.add_argument("-v", "--verbose", help="increase output verbosity", action="store_true")
@dgroft
dgroft / async_lambda_with_callback.cs
Last active August 29, 2015 13:56
Asynchronously invoke a lambda and invoke a callback lambda upon completion back on the main thread. Helpful in the event you're unable to enjoy TPL or async/await.
using System.Runtime.Remoting.Messaging;
using System.Threading;
// capture the ui thread context for completion callback
private SynchronizationContext context = SynchronizationContext.Current;
Action action = () => {
/* do some stuff */
};
@dgroft
dgroft / unity_editor_window_progress_bar.cs
Created February 17, 2014 19:56
Create a progress bar embedded in a Unity editor window
Rect r = EditorGUILayout.BeginVertical();
EditorGUI.ProgressBar(r, 0.1f, "Doing something helpful");
GUILayout.Space(18);
EditorGUILayout.EndVertical();
@dgroft
dgroft / gist:dfb6db932ad93b4c26b3
Created July 9, 2014 18:36
Extract contents between parens in a string using RegEx
// fetch "grab this part!"
Regex.Match("blah blah (grab this part!)", @"\(([^)]*)\)").Groups[1].Value
// source: http://stackoverflow.com/questions/378415/how-do-i-extract-a-string-of-text-that-lies-between-two-parenthesis-using-net
@dgroft
dgroft / rename_files_using_regex
Last active August 29, 2015 14:06
Rename multiple files in a directory using Regex.
# rename multiple files in a directory using regex
# source: http://stackoverflow.com/questions/5574648/use-regex-powershell-to-rename-files
ls | %{ ren $_ $($_.name -replace '(TestFile_\w+)(\d+)(\.txt)', '${1}20140910${3}')}