Skip to content

Instantly share code, notes, and snippets.

View schotime's full-sized avatar

Adam Schroder schotime

  • Melbourne, Australia
View GitHub Profile
@schotime
schotime / gist:5693072
Created June 2, 2013 08:51
Override URL resolution
<img src="~/test.aspx" />
// This complies to
Response.Write("<img src=\"");
Response.Write(SiteResource("~/test.aspx"));
Response.Write("\" />");
// The problem is that the SiteResource method uses Request.ApplicationPath under the covers, but we are doing some
// URL rewriting so the URL is not the same as the ApplicationPath.
@schotime
schotime / dbconventions.cs
Created June 13, 2013 01:04
My Postgresql conventions
var conventions = FluentMappingConfiguration.Scan(scanner =>
{
scanner.Assembly(typeof(User).Assembly);
scanner.IncludeTypes(x=>x.Namespace.StartsWith(typeof(User).Namespace));
scanner.TablesNamed(x => Inflector.MakePlural(x.Name).BreakUpCamelCaseUsing("_").ToLower());
scanner.Columns.Named(x => x.Name.BreakUpCamelCaseUsing("_").ToLower());
scanner.PrimaryKeysNamed(x => x.Name.BreakUpCamelCaseUsing("_").ToLower() + "_id");
scanner.OverrideMappingsWith(new OverrideMappings());
});
@schotime
schotime / EnumerableReader.cs
Created July 3, 2013 04:00
EnumerableReader
public class EnumerableReader : TextReader
{
private readonly char _separator;
private readonly IEnumerator<string> _enumerator;
private string _s;
private int _pos;
private readonly bool _useSeperator;
private bool _enumeratorDisposed = false;
public EnumerableReader(IEnumerable<string> lines) : this(lines, '\n')
@schotime
schotime / HStore.cs
Created August 23, 2013 02:11
PostgreSQL NPoco configuration with HStore and DateTimeOffset support
public class HStore : Dictionary<string, string>
{
private static readonly Regex QuotedString = new Regex(@"""[^""\\]*(?:\\.[^""\\]*)*""", RegexOptions.Compiled);
private static readonly Regex UnquotedString = new Regex(@"(?:\\.|[^\s,])[^\s=,\\]*(?:\\.[^\s=,\\]*|=[^,>])*", RegexOptions.Compiled);
private static readonly Regex HstoreKeyPairMatch = new Regex(string.Format(@"({0}|{1})\s*=>\s*({0}|{1})", QuotedString, UnquotedString), RegexOptions.Compiled);
private static readonly Regex KeyReg = new Regex(@"^""(.*)""$", RegexOptions.Compiled);
private static readonly Regex KeyReg2 = new Regex(@"\\(.)", RegexOptions.Compiled);
private static readonly Regex EscapeRegex = new Regex(@"[=\s,>]", RegexOptions.Compiled);
private static readonly Regex EscapeRegex2 = new Regex(@"([""\\])", RegexOptions.Compiled);
https://www.typescriptlang.org/play/index.html#src=interface%20IContext%3CT%3E%20%7B%0D%0A%09input%3A%20any%2C%0D%0A%09state%3A%20any%2C%0D%0A%09output%3A%20T%2C%0D%0A%09services%3A%20any%0D%0A%7D%0D%0A%0D%0Atype%20IRes%20%3D%20IResult%20%7C%20void%0D%0A%0D%0Ainterface%20IResult%20%7B%0D%0A%09success%3A%20((input%3A%20any)%20%3D%3E%20IRes)%2C%0D%0A%09error%3A%20((input%3A%20any)%20%3D%3E%20IRes)%0D%0A%7D%0D%0A%0D%0Aclass%20SignalBuilder%20%7B%0D%0A%09private%20signals%20%3D%20%5B%5D%3B%0D%0A%09dor%3CT%3E(func%3A%20(input%3A%20IContext%3CT%3E)%20%3D%3E%20void)%3A%20SignalBuilderResult%3CT%3E%20%7B%0D%0A%09%09this.signals.push(func)%3B%0D%0A%09%09return%20new%20SignalBuilderResult%3CT%3E(this%2C%20this.signals)%3B%0D%0A%09%7D%0D%0A%09do%3CT%3E(...func%3A%20((input%3A%20IContext%3CT%3E)%20%3D%3E%20void)%5B%5D)%3A%20SignalBuilder%20%7B%0D%0A%09%09for%20(var%20item%20of%20func)%20this.signals.push(item)%3B%0D%0A%09%09return%20this%3B%0D%0A%09%7D%0D%0A%09build()%20%7B%0D%0A%09%09return%20this.signals%3B%0D%0A%09%7D
interface A<T> {
something: T
}
function call(arg: (input: A<void>) => void): () => void;
function call<T>(arg: (input: A<T>) => T): (input: T) => void {
return {} as any;
}
interface Input {