Skip to content

Instantly share code, notes, and snippets.

View kjeske's full-sized avatar

Krzysztof Jeske kjeske

View GitHub Profile
@kjeske
kjeske / ObjectExtensions.cs
Last active March 14, 2016 16:54
Safely get the property value from a source object. If the source object is null, then get the default value.
public static class ObjectExtensions
{
public static TReturn safe<T, TReturn>(this T testedObject, Func<T, TReturn> member, TReturn defaultValue = default(TReturn))
where T : class
{
return testedObject != null ? member(testedObject) : defaultValue;
}
}
// Usage example:
@kjeske
kjeske / clean.cmd
Created February 21, 2013 14:32 — forked from nikodemrafalski/clean.cmd
Clean bin and obj artifacts directories downstream current directory tree.
for /d /r . %%d in (bin, obj) do @if exist "%%d" rd /s/q "%%d"
@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
using (var context = new DatabaseContext())
{
context.Configuration.ValidateOnSaveEnabled = false;
// create product with existing ID
var product = new Product
{
Id = 928
};
@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">
@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 / 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 / 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 / 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);
#!/bin/bash
env=prod
app_repo=
app_name=
rm -r code/
git clone ${app_repo} code
cd code
mix deps.get --only ${env}