Skip to content

Instantly share code, notes, and snippets.

View lkaczanowski's full-sized avatar

Łukasz Kaczanowski lkaczanowski

View GitHub Profile
@lkaczanowski
lkaczanowski / RestSharpExtensions.cs
Created December 18, 2015 11:44
RestSharp extensions
using System;
using System.Net;
using System.Text;
using RestSharp;
namespace RestSharpExtensions
{
public static class RestSharpExtensions
{
@lkaczanowski
lkaczanowski / MockHttpMessageHandlerHelper.cs
Created December 16, 2015 14:57
HttpMessageHandler mock helper
internal static class MockHttpMessageHandlerHelper
{
public static void SetupSendAsync(this Mock<HttpMessageHandler> handler, Func<HttpResponseMessage> sendAsyncResultFunc)
{
handler.Protected()
.Setup<Task<HttpResponseMessage>>("SendAsync", ItExpr.IsAny<HttpRequestMessage>(), ItExpr.IsAny<CancellationToken>())
.Returns(Task<HttpResponseMessage>.Factory.StartNew(sendAsyncResultFunc));
}
public static void VerifySendAsync(this Mock<HttpMessageHandler> handler, Times times)
@lkaczanowski
lkaczanowski / SequenceGenerator.cs
Last active November 3, 2019 11:35
Method to generate infinite iterations of elements with IEnumerable and IAsyncEnumerable
public static class SequenceGenerator
{
public static IEnumerable<T> Generate<T>(T initialValue, Func<T, T> generator)
where T : struct
{
var value = initialValue;
while (true)
{
yield return value;
value = generator(value);
@lkaczanowski
lkaczanowski / NugetHelpers.ps1
Last active August 29, 2015 14:22
Nuget Powershell Helpers
Register-TabExpansion 'Get-SolutionPackages' @{
'PackageName' = { Get-Package | Sort-Object -Property Id -Unique | foreach { $_.Id } }
}
Register-TabExpansion 'Refresh-Package' @{
'PackageName' = { Get-Package | Sort-Object -Property Id -Unique | foreach { $_.Id } }
}
function Refresh-Package($PackageName) {
@lkaczanowski
lkaczanowski / MvcModelBinderTestHelper.cs
Last active August 29, 2015 14:14
MVC ModelBinder test helper
public static class MvcModelBinderTestHelper
{
public static ModelBindingContext FakeModelBindingContext<T>(NameValueCollection formCollection) where T : class
{
var valueProvider = new NameValueCollectionValueProvider(formCollection, null);
var metadata = ModelMetadataProviders.Current.GetMetadataForType(null, typeof(T));
var bindingContext = new ModelBindingContext
{
@lkaczanowski
lkaczanowski / HtmlActionResult
Created August 6, 2014 12:25
Implementation of ASP.NET Web.Api IHttpActionResult that returns html rendered by Razor
public class HtmlActionResult<T> : IHttpActionResult
{
private readonly string _viewTemplate;
private readonly T _model;
public HtmlActionResult(string viewTemplateFullPath, T model)
{
_viewTemplate = File.ReadAllText(viewTemplateFullPath);
_model = model;
}
(function() {
d3.force_labels = function force_labels() {
var labels = d3.layout.force();
// Update the position of the anchor based on the center of bounding box
function updateAnchor() {
if (!labels.selection) return;
labels.selection.each(function(d) {
var bbox = this.getBBox(),
x = bbox.x + bbox.width / 2,
@lkaczanowski
lkaczanowski / GetSolutionPackages
Last active August 29, 2015 14:02
Lists installed packages per project in solution
Register-TabExpansion 'Get-SolutionPackages' @{
'PackageName' = { Get-Package | Sort-Object -Property Id -Unique | foreach { $_.Id } }
}
function Get-SolutionPackages($PackageName) {
$nl = [Environment]::NewLine
$packageSummaryList = @()
Get-Project -All | ForEach-Object {
@lkaczanowski
lkaczanowski / ApiControllerWithSignalR.cs
Last active August 29, 2015 13:57
ApiController with SignalR
// taken from: https://github.com/bradwilson/ndc2012/tree/master/NdcDemo
public abstract class ApiControllerWithHub<THub> : ApiController
where THub : IHub
{
private readonly Lazy<IHubContext> _hub = new Lazy<IHubContext>(
() => GlobalHost.ConnectionManager.GetHubContext<THub>()
);
protected IHubContext Hub
@lkaczanowski
lkaczanowski / Install.ps1
Created February 21, 2014 10:14
Nuget install script - copy folder from package to other directory
param($installPath, $toolsPath, $package, $project)
$projectFullName = $project.FullName
Write-Host "Copying Docs folder to the root of the solution: $projectFullName"
$fileInfo = new-object -typename System.IO.FileInfo -ArgumentList $projectFullName
$projectDirectory = $fileInfo.DirectoryName
$sourceDirectory = "$installPath\docs"
Write-Host $sourceDirectory