Skip to content

Instantly share code, notes, and snippets.

@niaher
niaher / Resources.tt
Last active January 11, 2024 16:00
T4 template to generate list of files that are part of the project. This template is useful for generating list of css/js resources to be put in bundle. The value comes from the fact that files which are not part of the project (e.g. - excluded files) will not actually be included in the resulting list.
// This is an auto-generated file.
<#@ template language="C#" hostSpecific="true" debug="True" #>
<#@ output extension="cs" #>
<#@ assembly name="System.Core" #>
<#@ assembly name="EnvDte" #>
<#@ import namespace="System.Linq" #>
<#@ import namespace="System.IO" #>
<#@ import namespace="System.Collections.Generic" #>
<#@ import namespace="System.Text.RegularExpressions" #>
<#@ import namespace="System" #>
@niaher
niaher / excel-download-images-from-url
Last active July 16, 2023 00:22
Excel macro (VBA script) to download images based on the URL specified in the cells
Private Declare Function URLDownloadToFile Lib "urlmon" Alias _
"URLDownloadToFileA" (ByVal pCaller As Long, _
ByVal szURL As String, _
ByVal szFileName As String, _
ByVal dwReserved As Long, _
ByVal lpfnCB As Long) As Long
Public Sub GURoL(url As String, FileName As String)
Dim lngRetVal As Long
lngRetVal = URLDownloadToFile(0, url, FileName, 0, 0)
@niaher
niaher / test-sql-server-connectivity
Created October 25, 2021 00:51
Test connectivity to a local or remote SQL Server database using PowerShell
function Test-SqlConnection {
param(
[Parameter(Mandatory)]
[string]$ConnectionString
)
$ErrorActionPreference = 'Stop'
try {
$sqlConnection = New-Object System.Data.SqlClient.SqlConnection $ConnectionString
@niaher
niaher / Create login and user
Created July 25, 2013 08:48
Creates SQL login and user for a database. The user is created with 3 roles: db_executor, db_datareader, db_datawriter.
/*------------------------------------------------------------------------------------
Server login
-----------------------------------------------------------------------------------*/
if not exists (select 1 from sys.server_principals where name = N'MyDatabaseUser')
create login [MyDatabaseUser]
with password = 'password',
default_database = [MyDatabase],
check_policy = off,
check_expiration = off
go
@niaher
niaher / gist:f09803834dd133d7b215
Created July 2, 2015 11:35
List identical files in 2 folders
$one = Get-ChildItem "C:\x" -Recurse -Include @("*.html", "*.js")
$two = Get-ChildItem "C:\y" -Recurse -Include @("*.html", "*.js")
Compare-Object -ReferenceObject $one -DifferenceObject $two -Property Name,Length -ExcludeDifferent -IncludeEqual
@niaher
niaher / gist:cccc35ae58076095784e
Created July 9, 2015 11:19
Update column counter per group
;with Counters as (
select Id,
row_number() over (partition by GroupingColumn order by GroupingColumn asc) as [Counter]
from RequisitionLine
)
update T
set T.[Counter] = C.[Counter]
from MyTable T inner join Counters C on T.Id = C.Id
@niaher
niaher / server-setup.ps1
Last active April 2, 2019 08:17
This script configures IIS application pool and site. It needs to be run once on each machine where the app is deployed. Run it in powershell with admin rights. For example to deploy release config run `server-setup.ps1 -Target release`
# This script configures IIS application pool and site.
# This script needs to be run once on each machine where the app is deployed.
# Run this file in powershell with admin rights. For example to deploy release config:
# PS > server-setup.ps1 -Target release
param (
[Parameter(Mandatory=$true,
HelpMessage="Name of the build (e.g. - local, debug, release, etc)")]
[string]$Target
)
# This script configures IIS application pool and app.
# example usage:
# PS> init-server.ps1 -AppName MyApp -TargetComputers computer1,computer2 -PSSessionUser $(PSSessionUser) -PSSessionPassword $(PSSessionPassword) -AppPoolUser $(AppPoolUser) -AppPoolPassword $(AppPoolPassword)
param(
[Parameter(Mandatory=$true)][string]$AppName,
[string]$TargetComputers,
[string]$PSSessionUser,
[string]$PSSessionPassword,
[string]$AppPoolUser,
@niaher
niaher / deploy-sqlproj
Last active April 2, 2019 08:16
MSDeploy script
msbuild "MyApp.Database/MyApp.Database.sqlproj" `
/t:"Build;Publish" `
/p:SqlPublishProfilePath="MyApp.Database.automated-tests.publish.xml" `
/p:UpdateDatabase=True `
/p:PublishScriptFileName="publish-script.sql"

Keybase proof

I hereby claim:

  • I am niaher on github.
  • I am niaher (https://keybase.io/niaher) on keybase.
  • I have a public key ASBktBkUBBhH4rZTMKTq-GQt26QcxCoLnnj4-F9hNkQK5go

To claim this, I am signing this object: