Skip to content

Instantly share code, notes, and snippets.

View lkaczanowski's full-sized avatar

Łukasz Kaczanowski lkaczanowski

View GitHub Profile
@lkaczanowski
lkaczanowski / CustomHandleErrorAttribute.cs
Last active November 14, 2020 00:33
Custom ASP.NET MVC handle error attribute. Handles and logs all errors.
public class CustomHandleErrorAttribute : HandleErrorAttribute
{
private static readonly ILog _log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
public override void OnException(ExceptionContext filterContext)
{
if (!filterContext.HttpContext.IsCustomErrorEnabled)
{
return;
}
/**
* WkHtmlToPdf table splitting hack.
*
* Script to automatically split multiple-pages-spanning HTML tables for PDF
* generation using webkit.
*
* To use, you must adjust pdfPage object's contents to reflect your PDF's
* page format.
* The tables you want to be automatically splitted when the page ends must
* have a class name of "splitForPrint" (can be changed).
@lkaczanowski
lkaczanowski / Global.asax.cs
Created August 27, 2013 07:14
MVC Global error handling
protected void Application_Error(Object sender, EventArgs e)
{
var httpContext = ((MvcApplication)sender).Context;
var currentRouteData = RouteTable.Routes.GetRouteData(new HttpContextWrapper(httpContext));
var currentController = " ";
var currentAction = " ";
if (currentRouteData != null)
{
@lkaczanowski
lkaczanowski / install.ps1
Created October 18, 2013 07:17
Powershell nuget script to copy log4net.config file to project depending on project type
param($installPath, $toolsPath, $package, $project)
$projectItems = $project.ProjectItems
$isWPFProject = Select-String -Simple "{60DC8134-EBA5-43B8-BCC9-BB4BC16C2548}" $project.FullName #WPF project guid
$isWinFormsProject = Select-String -Simple "FlavorProperties" $project.FullName #WinForms project doesn't support FlavorProperties so should be empty
if(([string]::IsNullOrEmpty($isWPFProject) -eq $false) -or ([string]::IsNullOrEmpty($isWinFormsProject) -eq $true)) {
#terminal app project
Write-Host "Detected terminal application project (WebForms or WPF)"
$projectItems.Item("log4net.config").Delete()
@lkaczanowski
lkaczanowski / NotifyPropertyBase.cs
Created January 28, 2014 10:41
INotifyPropertyChanged with property expressions
public class NotifyPropertyBase : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged( Expression<Func<object>> propertyExpression )
{
PropertyChangedEventHandler handler = PropertyChanged;
if (handler != null) handler( this, new PropertyChangedEventArgs( GetPropertyName( propertyExpression ) ) );
}
private string GetPropertyName( Expression<Func<object>> propertyExpression )
@lkaczanowski
lkaczanowski / jquery.debounce.js
Created February 3, 2014 07:26
JQuery Debounce
(function ($) {
'use strict';
$.debounce = function (delay, fn) {
var timer = null;
return function () {
var context = this, args = arguments;
clearTimeout(timer);
timer = setTimeout(function () {
fn.apply(context, args);
}, delay);
@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
@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 / 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 {
(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,