Skip to content

Instantly share code, notes, and snippets.

@mganss
mganss / download_xsd.csx
Created January 18, 2022 17:14
Recursively download XML schema definition files (xsd files)
#! "net6.0"
using System.Net.Http;
using System.Xml;
using System.Xml.Linq;
var opts = Args.Where(a => a.StartsWith("-"));
if (Args.Except(opts).Count() < 1)
{
@mganss
mganss / NonHtml.cs
Created November 10, 2016 16:40
Encode non-HTML before HTML sanitization
static Regex HtmlRegex = new Regex(@"</?([a-z]+[1-6]?)", RegexOptions.IgnoreCase);
static HashSet<string> HtmlTags = new HashSet<string>(StringComparer.OrdinalIgnoreCase) { "a", "abbr", "acronym", "address", "applet", "area", "article", "aside", "audio", "b", "base", "bdi", "bdo", "big", "blockquote", "body", "br", "button", "canvas", "caption", "center", "cite", "code", "col", "colgroup", "command", "datalist", "dd", "del", "details", "dfn", "dir", "div", "dl", "dt", "em", "embed", "fieldset", "figcaption", "figure", "font", "footer", "form", "frame", "h1", "h2", "h3", "h4", "h5", "h6", "head", "header", "hgroup", "hr", "html", "i", "iframe", "img", "input", "ins", "isindex", "kbd", "keygen", "label", "legend", "li", "link", "map", "mark", "menu", "meta", "meter", "nav", "noscript", "object", "ol", "optgroup", "option", "output", "p", "param", "pre", "progress", "q", "rp", "rt", "ruby", "s", "samp", "script", "section", "select", "small", "source", "span", "strike", "strong", "style", "sub", "summary", "sup"
@mganss
mganss / IS24Csv.md
Last active August 29, 2015 14:08
IS24 CSV C#/XML Class Model

C# Class Model for IS24 CSV

This gist includes a class model in C# and XML of the ImmobilienScout24 CSV import file format. The files were generated from the tables contained in the official documentation (CSV_Import_IS24.doc, version 1.4.1.3).

The C# class model tries to provide as much static type information as can be gleaned from the documentation, in particular:

  • Number fields:
  • int or decimal depending on the size description or
  • enum if there are discrete values listed in the description
  • Text fields:
@mganss
mganss / SkinScanner.md
Last active July 15, 2019 08:14
Simple human skin color detection

C# port of a simple skin color detection algorithm. Python original by SpliFF here. See also this Stack Overflow question.

Produces a lot of false positives but is great for quickly filtering a large set of unknown images.

@mganss
mganss / BaseXmlDeserializer.md
Last active December 16, 2015 21:39
A RestSharp XML deserializer that can deserialize derived classes.

Assume you have these classes:

public class Base
{
}

public class Derived : Base
{
}
@mganss
mganss / Pool.cs
Created January 2, 2013 12:55
A buffer pool and an in-memory stream that uses it.
using System;
using System.Collections.Concurrent;
namespace XY
{
public interface IPool<T>
{
T Take();
void Return(T t);
}