Skip to content

Instantly share code, notes, and snippets.

Measure-Command { & C:\mybatfile.bat | Out-Default}
@alfeg
alfeg / Program.cs
Last active March 30, 2016 16:00
String split - manual vs regex
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;
namespace BenchITSplit
{
class Program
find *.png -type f -exec curl -i -F filedata=@{} http://servername/image \;
### Keybase proof
I hereby claim:
* I am alfeg on github.
* I am alfeg (https://keybase.io/alfeg) on keybase.
* I have a public key ASAos-cuH6vcwnT76XrUspk4nCNb4Wux4V5mQY_vQVemVgo
To claim this, I am signing this object:
@alfeg
alfeg / Wrappers.cs
Created February 24, 2017 15:51
Jerbrain.profile wrappers
public class DotMemoryProfile : IDisposable
{
public DotMemoryProfile()
{
if (MemoryProfiler.IsActive && MemoryProfiler.CanControlAllocations)
MemoryProfiler.EnableAllocations();
MemoryProfiler.Dump();
}
public void Dispose()
@alfeg
alfeg / OneToManyAttribute.cs
Last active June 15, 2017 06:52
SqliteLiteExtensions.cs
public class OneToManyAttribute : RelationAttribute
{
public string ForeignKey { get; }
public OneToManyAttribute(string foreignKey)
{
this.ForeignKey = foreignKey;
}
public override void SetProperty(PropertyInfo info)
public class PerHostJsonConfigBuilder : ConfigurationBuilder
{
public string Directory { get; set; }
JObject hostConfig = null;
public override void Initialize(string name, NameValueCollection config)
{
base.Initialize(name, config);
JObject LoadByHostName(string host)
@alfeg
alfeg / Project.csproj
Last active September 5, 2018 11:04
MSBuild target file that handle Grpc.Tools generation, And example on how to include
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Google.Protobuf" Version="3.6.1" />
<PackageReference Include="Grpc" Version="1.14.2" />
<PackageReference Include="Grpc.Tools" Version="1.14.2" />
</ItemGroup>
@alfeg
alfeg / split.ps1
Created November 5, 2018 08:16
Split m4v video file at some point of time
param([string] $i, [string] $time, [string] $output)
ffmpeg -i $i -acodec copy -vcodec copy -to $time "$output-1.m4v"
ffmpeg -i $i -acodec copy -vcodec copy -ss $time "$output-2.m4v"
@alfeg
alfeg / PartialFileContentResult.cs
Last active November 8, 2018 20:31
PartialFileContentResult to return 206 partial responses from MVC 5
public class PartialFileContentResult : ActionResult
{
private readonly Stream stream;
private readonly string contentType;
private readonly CancellationToken token;
/// <summary>Initializes a new instance of the <see cref="T:System.Web.Mvc.FileContentResult" /> class by using the specified file contents and content type.</summary>
/// <param name="fileContents">The byte array to send to the response.</param>
/// <param name="contentType">The content type to use for the response.</param>
/// <exception cref="T:System.ArgumentNullException">The <paramref name="fileContents" /> parameter is null.</exception>