Skip to content

Instantly share code, notes, and snippets.

using System.Text.RegularExpressions;
using System;
const string smallRectangles = "1\n\n2\n\n~~\n\n";
Regex normal = new Regex(Rect.RectanglesPatternShorter, RegexOptions.Multiline | RegexOptions.Singleline | RegexOptions.IgnorePatternWhitespace);
Regex compiled = new Regex(Rect.RectanglesPatternShorter, RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.Singleline | RegexOptions.IgnorePatternWhitespace);
Console.WriteLine("normal: " + normal.IsMatch(smallRectangles));
Console.WriteLine("compiled: " + compiled.IsMatch(smallRectangles));
public static readonly string RectanglesPattern = @"
\A
(?=(?<NextPos>[^~]*)) # \k<NextPos> always matches the position *before* the next free tilde.
(?:
(?:
(?<IndexLength>.)+? # Match n characters. We will use rectangle number n in position <Index>.
# 0 is not an option - we need some shape to be first, second, third, etc.
(?<=\A(?=(?<Index>(?<-IndexLength>.)+)).*) # Capture into <Index> the first n characters.
(?<=\A(?<CurrentIndex>\k<Index>).*) # Copy Index into CurrentIndex
(?=.*\Z # Ensure <Index> is unique. We cannot use the same rectangle twice
@kobi
kobi / BulkOperationsExtensions.cs
Created August 4, 2020 09:10
Example code for Entity Framework 6 – Bulk Insert and Returning of Generated Primary Keys https://kobikobi.wordpress.com/2018/02/05/entity-framework-6-bulk-insert-and-returning-of-generated-primary-keys/
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Data.Entity;
using System.Data.SqlClient;
using System.Linq;
using System.Linq.Expressions;
using EntityFramework.Utilities;
body {background-color: dodgerblue;}
@kobi
kobi / inMemoryModel.js
Last active July 18, 2022 13:05
NodeJs and OAuth2 - Updated example of using express-oauth-server with a memory model
// based on https://github.com/oauthjs/express-oauth-server/blob/master/examples/memory/model.js
/**
* Constructor.
*/
function InMemoryCache() {
this.clients = [
{
clientId : 'dummy-client-id',
clientSecret : 'dummy-client-secret',
@kobi
kobi / Stack Overflow Navigation Bar - Light.css
Last active September 19, 2017 12:58
Stack Overflow Navigation Bar - Light
/*
Author: Kobi
Version: 0.4
Name: Stack Overflow New Navigation Bar - Light non-sticky
*/
@-moz-document domain("stackoverflow.com") {
header.top-bar {
background-color: #f3f3f3;
border-top:none;
@kobi
kobi / Mapping.generated.cs
Last active August 29, 2015 14:20
Example output for Stack Overflow question: How to simplify repeating if-then-assign construction? - http://stackoverflow.com/a/29918452/7586
// !!!
// !!! Do not modify this file, it is automatically generated. Change the .tt file instead. !!!
// !!!
namespace Your.Mapper
{
partial class Mapper
{
/// <summary>
/// Set <paramref name="target"/> properties by copying them from <paramref name="source"/>.
@kobi
kobi / Mapping.tt
Last active August 29, 2015 14:20
Example output for Stack Overflow question: How to simplify repeating if-then-assign construction? - http://stackoverflow.com/a/29918452/7586
<#@ template debug="false" hostspecific="false" language="C#" #>
<#@ assembly name="System.Core" #>
<#@ assembly name="$(TargetPath)" #>
<#@ import namespace="System.Collections.Generic" #>
<#@ import namespace="System.Linq.Expressions" #>
<#@ import namespace="ConsoleApplicationT4So29913514" #>
<#@ output extension=".generated.cs" #>
<#
// Consider including the namespace in the class names.
// You only need to change the mappings.
@kobi
kobi / ModifyExistingEntityMapping.cs
Last active August 29, 2015 14:20
Example output for Stack Overflow question: How to simplify repeating if-then-assign construction? - http://stackoverflow.com/a/29918452/7586
// !!!
// !!! Do not modify this file, it is automatically generated. Change the .tt file instead. !!!
// !!!
namespace Your.Mapper
{
partial class Mapper
{
/// <summary>
/// Set <paramref name="target"/> properties by copying them from <paramref name="source"/>.
/// </summary>
@kobi
kobi / gist:8156968
Created December 28, 2013 07:27
Answer to http://stackoverflow.com/q/3349999/7586 , with captures of A and Q.
\A
# Push State A, Index = 0
(?<StateIdBit0>)
(?<StateIdBit1>)
(?<StateIdBit2>)
(?<StateIdBit3>)
(?:
(?:
(?:
# When In State A, Index = 0