Skip to content

Instantly share code, notes, and snippets.

View kjeske's full-sized avatar

Krzysztof Jeske kjeske

View GitHub Profile
param ([string]$excelFileName)
Set-ExecutionPolicy Bypass -Scope Process
[System.Threading.Thread]::CurrentThread.CurrentCulture = New-Object "System.Globalization.CultureInfo" "en-US"
Function ExportWSToCSV ($excelPath, $csvFileName)
{
$excelFile = Get-Item $excelPath
$excelLocation = $excelFile.DirectoryName
$E = New-Object -ComObject Excel.Application
@kjeske
kjeske / ObjectExtensions.cs
Last active May 7, 2019 09:21
Immutable changes in objects using AutoMapper
public static class ObjectExtensions
{
private static readonly ConcurrentDictionary<Type, Func<object, object>> MemberwiseCloneCache =
new ConcurrentDictionary<Type, Func<object, object>>();
public static T With<T>(this T obj, Action<T> mutator) where T : class
{
if (obj == null)
{
return null;
#!/bin/bash
env=prod
app_repo=
app_name=
rm -r code/
git clone ${app_repo} code
cd code
mix deps.get --only ${env}
@kjeske
kjeske / ModelStateDictionaryExtensions.cs
Created September 15, 2014 10:39
AddModelError(Model, x=>x.PropertyName, "text")
namespace System.Web.Mvc
{
using Linq.Expressions;
public static class ModelStateDictionaryExtensions
{
public static void AddModelError<TEntity, TValue>(this ModelStateDictionary modelState, TEntity model, Expression<Func<TEntity, TValue>> member, string value)
{
var memberPath = ExpressionHelper.GetExpressionText(member);
modelState.AddModelError(memberPath, value);
@kjeske
kjeske / project.csproj
Last active August 29, 2015 14:06
Run web.config transformations on local machine before build.
<Target Name="BeforeBuild" DependsOnTargets="CreateVersionInfo">
<TransformXml Source="web.base.config" Transform="web.orig.$(Configuration).config" Destination="web.config" />
</Target>
@kjeske
kjeske / StreamExtensions.cs
Created August 7, 2014 09:29
Stream.ToByteArray
namespace System.IO
{
public static class StreamExtensions
{
public static byte[] ToByteArray(this Stream inputStream)
{
using (var memoryStream = new MemoryStream())
{
inputStream.Position = 0;
inputStream.CopyTo(memoryStream);
@kjeske
kjeske / File-with-validation.js
Last active January 4, 2016 22:09
File input with extension validation in jQuery Validation
<input
data-val="true"
data-val-extension="Wrong extension"
data-val-extension-list="jpg|jpeg"
type="file"
/>
// Add reference to additional-methods.js from http://jqueryvalidation.org
// Add at the end of the jquery.validate.unobtrusive.js
@kjeske
kjeske / gist:8538737
Created January 21, 2014 11:57
How to handle custom errors handling in ASP MVC 4+ and IIS 7+
<system.web>
<customErrors
mode="RemoteOnly"
// ResponseRewrite would be a better way, but is uses Server.Transfer so we have to use
// ResponseRedirect which redirects whole page. To do this better you have to wrap 404 errors
// in Application_Error
redirectMode="ResponseRedirect"
defaultRedirect="Error">
using (var context = new DatabaseContext())
{
context.Configuration.ValidateOnSaveEnabled = false;
// create product with existing ID
var product = new Product
{
Id = 928
};
@kjeske
kjeske / bootable.cmd
Created February 27, 2013 20:26
Create bootable usb drive for windows 7/8 installation
DiskPart
List Disk
Select Disk #
Clean
Create Partition Primary
Select Partition 1
Active
Format fs=FAT32 quick
Assign