Skip to content

Instantly share code, notes, and snippets.

View raducugheorghe's full-sized avatar

Raducu Gheorghe raducugheorghe

  • Romania
View GitHub Profile
@raducugheorghe
raducugheorghe / change_EF_database.ps1
Created February 20, 2017 10:30
Change EF database name in connection string tool
$files = Get-ChildItem -Include Web.config -recurse | Select-String -pattern 'Database=[a-zA-Z_0-9\-]+;' | select path,matches
if ($files.length -eq 0 )
{
Write-Host "no files found" -ForegroundColor red
exit 0
}
Write-Host "Found the following matches:" -ForegroundColor green
@raducugheorghe
raducugheorghe / MinifyInlineScriptsAttribute.cs
Last active March 21, 2017 16:55
[C#][MVC] Minify inline scripts and styles
public class MinifyInlineScriptsAttribute : ActionFilterAttribute
{
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
var originalFilter = filterContext.HttpContext.Response.Filter;
if(originalFilter != null) filterContext.HttpContext.Response.Filter = new MinifyStream(originalFilter);
base.OnActionExecuting(filterContext);
}
@raducugheorghe
raducugheorghe / [Powershell] RemoveFromGac.ps1
Last active March 1, 2016 08:52
Remove all dll-s in curent folder from GAC
[System.Reflection.Assembly]::Load("System.EnterpriseServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")
$publish = New-Object System.EnterpriseServices.Internal.Publish
foreach ($file in Get-ChildItem *.dll) {
echo $file.FullName
$publish.GacRemove($file.FullName)
}
@raducugheorghe
raducugheorghe / [Powershell] InstallToGac.ps1
Last active June 15, 2017 15:46
Install all dll-s in curent folder to GAC
[System.Reflection.Assembly]::Load("System.EnterpriseServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")
$publish = New-Object System.EnterpriseServices.Internal.Publish
foreach ($file in Get-ChildItem *.dll) {
echo $file.FullName
$publish.GacInstall($file.FullName)
}
@raducugheorghe
raducugheorghe / ListShuffleExtension.cs
Created January 6, 2016 16:59
List shuffle (randomizer)
public static class ThreadSafeRandom
{
[ThreadStatic]
private static Random _local;
public static Random ThisThreadsRandom => _local ?? (_local = new Random(unchecked(Environment.TickCount * 31 + Thread.CurrentThread.ManagedThreadId)));
}
public static class ListShuffleExtension
{
<#
.Synopsis
Trigger a TeamCity backup using the TeamCity REST API.
.Parameter username
Defines a TeamCity username which has authority to trigger backups.
.Parameter password
Defines the password for the user which will trigger the backup.
.Parameter baseUrl
Defines the URL to the TeamCity server (eg: http://teamcity.example.com).
If not set, the script will attempt to determine it from the TeamCity properties file.
@raducugheorghe
raducugheorghe / Mvc DateTime With EditFormat model binder
Created March 13, 2015 09:46
[C#][MVC] DateTime model binder that uses EditFormatString for parsing
public class DateTimeWithEditFormatModelBinder : DefaultModelBinder
{
public override object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
{
if (bindingContext.ModelType == typeof(DateTime?) || bindingContext.ModelType == typeof(DateTime))
{
var displayFormat = bindingContext.ModelMetadata.EditFormatString;
var value = bindingContext.ValueProvider.GetValue(bindingContext.ModelName);
@raducugheorghe
raducugheorghe / Mvc abstract factory model binder
Last active August 29, 2015 14:17
[C#][MVC] Abstract factory model binder
public class AbstractFactoryModelBinder : DefaultModelBinder
{
public override object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
{
var modelType = bindingContext.ModelType;
if (modelType.IsAbstract)
{
var value = bindingContext.ModelName == "model" ? bindingContext.ValueProvider.GetValue("Type") : bindingContext.ValueProvider.GetValue(bindingContext.ModelName + ".Type");
if (value == null)
throw new ApplicationException("View does not contain Type");
@raducugheorghe
raducugheorghe / KnockoutJs Numeric Extender
Last active August 29, 2015 14:16
[Javascript][Knockout] Numeric extender
ko.extenders.numeric = function (target, params) {
var options = {
precision: 0,
allowNegative: false
};
$.extend(options, params);
//create a writable computed observable to intercept writes to our observable
var result = ko.pureComputed({
read: target, //always return the original observables value
@raducugheorghe
raducugheorghe / Backup app from sql job
Created February 6, 2015 09:05
[TransactSQL] Backup website and database from SQL job (uses winrar)
1. Map network drive
EXEC XP_CMDSHELL 'net use W: \\mainstore\Backup PASSWORD /user:USERNAME'
2. Backup Database
declare
@timestamp varchar(8),
@fileName varchar(1024)