Skip to content

Instantly share code, notes, and snippets.

@shiranGinige
shiranGinige / ChangeAllReferences.ps1
Created September 21, 2012 09:40
Powershell script to changes references of all projects under the execution directory
# Calling Convention
# ChangeReference.ps1 "log4net , Version=1.2.0.0 ......" "new dll path" , "log4net , <new dll infor>"
# Note : This needs script signing before executing. refer http://www.hanselman.com/blog/SigningPowerShellScripts.aspx
# OR can set the powershell execution policy to unrestricted (at your own risk ;)) > Set-ExecutionPolicy unrestricted
param([String]$ReferenceToRemove , [String]$NewAssemblyPath, [String]$NewAssemblyIncludeInfo)
$xmlns = "http://schemas.microsoft.com/developer/msbuild/2003"
$projects = ls -r -i *.csproj
@shiranGinige
shiranGinige / RemoveReferences.ps1
Created September 21, 2012 09:52
Powershell script to remove a given reference from all cs projects under the execution directory
# Calling Convention
# ChangeReference.ps1 "log4net , Version=1.2.0.0 ......" "new dll path" , "log4net , <new dll infor>"
# Note : This needs script signing before executing. refer http://www.hanselman.com/blog/SigningPowerShellScripts.aspx
# OR can set the powershell execution policy to unrestricted (at your own risk ;)) > Set-ExecutionPolicy unrestricted
param([String]$ReferenceToRemove )
$xmlns = "http://schemas.microsoft.com/developer/msbuild/2003"
$projects = ls -r -i *.csproj
@shiranGinige
shiranGinige / FindProjectsWithGivenReference.ps1
Created September 21, 2012 09:54
To find cs project files that has referred the given assembly
# Calling Convention
# FindReference.ps1 "log4net"
param([String]$ReferenceToFind )
$xmlns = "http://schemas.microsoft.com/developer/msbuild/2003"
$projects = ls -r -i *.csproj
foreach($projectPath in $projects)
{
$proj = [string](Get-Content $projectPath)
@shiranGinige
shiranGinige / gist:3760721
Created September 21, 2012 10:02
Macro to attach a w3wp to debugger. Should set this as a keyboard shortcut after saving this.
Imports System
Imports EnvDTE
Imports EnvDTE80
Imports EnvDTE90
Imports EnvDTE90a
Imports EnvDTE100
Imports System.Diagnostics
Public Module Module1
' This subroutine attaches to calc.exe if it is running.
# This script combines all .sql files under a given directory in to a file name matched to
# the sub-directory name (Tables.sql for all .sql files under the /Tables directory).
# And then create a AllScripts.sql by merging everything together.
# This can be executed by setting the "> Set-ExecutionPolicy unrestricted" in the windows powershell
Remove-Item *.sql
Get-Content Database\*.sql | Add-Content 1_Database.sql
Get-Content Tables\*.sql | Add-Content 2_Tables.sql
Get-Content StoredProcedures\*.sql | Add-Content 3_StoredProcedures.sql
@shiranGinige
shiranGinige / gist:4726934
Created February 6, 2013 23:39
SQL script to restore a database courtesy : @adipa Gunasekara
USE MASTER
GO
declare @restoreSql nvarchar(500);
declare @dbName nvarchar(50);
declare @dbBackupFile nvarchar(100);
set @dbName = 'test';
set @dbBackupFile = 'test.bak';
@shiranGinige
shiranGinige / gist:5102758
Last active December 14, 2015 14:48
Ef4 Code First - collections in entities
If i do this with code first,
var entityA = new EntityA();
entityA.ItemCollection.Add(new Item());
entityA.ItemCollection.Add(new Item());
service.Save(entityA);
Everything works fine, until you go and check for the two records that should have been inserted
@shiranGinige
shiranGinige / Returning a file in a HTTP stream , without having a physical file
Last active December 26, 2015 15:38
I just want to save a file temporarily and return it as a stream for a HTTP response. Azure don't like me writing things to the file system? Here's how to get around.
var data = getData();
var stringBuilder = new StringBuilder();
stringBuilder.AppendLine("Header");
foreach (var item in data)
{
stringBuilder.AppendLine(data.Stuff)
}
var response = new HttpResponseMessage(HttpStatusCode.OK);
@shiranGinige
shiranGinige / gist:7927421
Created December 12, 2013 12:47
Storage comparison
Dropbox - 100 GB / 99 / year
Google drive 100 GB/ 180/ year
Skydrive 100GB/ 50 /year
https://skydrive.live.com/options/Upgrade
http://www.google.com/intx/en_au/enterprise/apps/business/products.html#product-drive-prices
https://www.dropbox.com/business/pricing
@shiranGinige
shiranGinige / gist:cff4f8a67b12ade8dd88
Last active August 29, 2015 14:01
Adding a user to Azure databases
Ok, here is our scenario. Create a database on an existing server, and 'sometimes' the applications are not able to access the database using the 'default' credentials assigned to the server. Following script can be used to do that manually.
CREATE USER theuser without login with default_schema=[dbo]
EXEC sp_addrolemember N'db_owner', N'theuser'