Skip to content

Instantly share code, notes, and snippets.

@musukvl
musukvl / ShardDbContext.cs
Created November 2, 2017 14:38
Using shared db context to create 100 000 records
using (var dbContext = new MainDbContext())
{
for (var i = 0; i < 100000; i++)
{
dbContext.Logs.Add(new Log()
{
Key = Guid.NewGuid().ToString("D"),
Data = "some random data:" + Guid.NewGuid().ToString("D"),
UpdatedDate = DateTime.UtcNow
});
@musukvl
musukvl / AsyncWhile1.cs
Last active January 15, 2018 21:33
AsyncWhile1.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
namespace TestApp
{
public class ParallelWhile
using System;
using System.Collections.Concurrent;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
namespace Common.Async
{
public class LimitedLengthActionPool : IDisposable
{
@musukvl
musukvl / sample.js
Created October 15, 2018 07:33
Node.js db access parallelism sample
async function getUserProfile(userId) {
let [user, groups] = await Promise.all([
db.getUser(userId),
db.getUserGroups(userId)
]);
return {userId, user, groups};
}
@musukvl
musukvl / web.config
Created January 10, 2019 20:29
Web,config for IIS url rewrite poxy from public domain to local port. Used for Teamcity
<?xml version="1.0" encoding="UTF-8"?>
<!---
config based on
https://blogs.msdn.microsoft.com/friis/2016/08/25/setup-iis-with-url-rewrite-as-a-reverse-proxy-for-real-world-apps/
https://blogs.msdn.microsoft.com/friis/2016/08/25/iis-with-url-rewrite-as-a-reverse-proxy-part-2-dealing-with-500-52-status-codes/
To you this configs you need to add
HTTP_ACCEPT_ENCODING
HTTP_X_ORIGINAL_ACCEPT_ENCODING
@musukvl
musukvl / Program.cs
Created December 26, 2018 17:37
ASP.NET Core Hello Word with SampleMiddleware
using System;
using System.Threading.Tasks;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
namespace WebApplication1
{
@musukvl
musukvl / async-context.js
Created January 14, 2019 18:28
Async context for your cli tools
function timeout(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
let result = (async function() {
await timeout(3000);
console.log("done");
})();
@musukvl
musukvl / MassTransitTest.cs
Created February 15, 2019 18:42
Mass transit concurrent sample
using System;
using System.Threading;
using GreenPipes;
using MassTransit;
namespace TestMassTransit
{
public class VideoFileMessage
{
public int Num { get; set; }
@musukvl
musukvl / WebApp.cs
Created March 16, 2019 06:42
.htaccess file for asp.net core application
// # .htaccess content sample
// RewriteRule ^/apache-mod-rules-redirect/(.*) /redirected?id=$1 [L,R=302]
using (StreamReader apacheModRewriteStreamReader =
File.OpenText(".htaccess"))
{
var options = new RewriteOptions()
.AddApacheModRewrite(apacheModRewriteStreamReader);
app.UseRewriter(options);
@musukvl
musukvl / GenerationController.cs
Created July 18, 2019 21:21
Example rendering IEnumerable to Asp.net core API action result
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
namespace ApiModelingApp.Controllers
{
[Route("api/generation")]
[ApiController]