Skip to content

Instantly share code, notes, and snippets.

View timgaunt's full-sized avatar

Tim Gaunt timgaunt

View GitHub Profile
@timgaunt
timgaunt / combine.ps1
Created March 7, 2018 07:12
Combine multiple csv or txt files together into one
$getFirstLine = $true;get-childItem "*.csv" | foreach {$filePath = $_;$lines = $lines = Get-Content $filePath;$linesToWrite = switch($getFirstLine) {$true {$lines}; $false {$lines | Select -Skip 1}};$getFirstLine = $false;Add-Content "combined.csv" $linesToWrite;}
function Compress-Subfolders
{
param
(
[Parameter(Mandatory = $true)][string] $InputFolder,
[Parameter(Mandatory = $true)][string] $OutputFolder
)
if (-not (test-path "$env:ProgramFiles\7-Zip\7z.exe")) {throw "$env:ProgramFiles\7-Zip\7z.exe needed"}
set-alias sz "$env:ProgramFiles\7-Zip\7z.exe"
@timgaunt
timgaunt / List Product Data.sql
Created February 20, 2017 18:17
List uCommerce product data in an importable format
USE MarkerTechV2CMS
GO
WITH Fields
AS
(
SELECT
pd.ProductDefinitionId [ChildDefinitionID]
, pd.ProductDefinitionId
, pd.Name AS [ProductDefinitionName]
@timgaunt
timgaunt / BusinessDaysUntil.cs
Created February 14, 2017 07:10
Calculate the number of business days between two dates
/// <summary>
/// Calculates number of business days, taking into account:
/// - weekends (Saturdays and Sundays)
/// - bank holidays in the middle of the week
/// </summary>
/// <param name="firstDay">First day in the time interval</param>
/// <param name="lastDay">Last day in the time interval</param>
/// <param name="bankHolidays">List of bank holidays excluding weekends</param>
/// <returns>Number of business days during the 'span'</returns>
public static int BusinessDaysUntil(this DateTime firstDay, DateTime lastDay, params DateTime[] bankHolidays)
DECLARE
@RowsToDelete INT = 100
, @rows INT = 1
, @batch INT = 1
, @batchestorun INT = 2000
, @message nvarchar(max)
, @keepOldVersionsCount int
, @keepNewerThanDate DATETIME
SET @keepOldVersionsCount = 0 /* 0 Keeps published and newest only. */
@timgaunt
timgaunt / Common Passwords.txt
Last active May 27, 2016 16:59
List of 500 common passwords to avoid
!QAZ1qaz
!QAZ2wsx
!Qaz2wsx
!QAZxsw2
!QAZzaq1
#EDC4rfv
123qweASD
12qw!@QW
1941.Salembbb.41
1qaz!QAZ
@timgaunt
timgaunt / Delete variants without prices.sql
Created May 18, 2016 07:41
Delete the variants (child products) from uCommerce where they don't have a price but the parent is active
BEGIN TRAN
SELECT TOP 100
*
FROM
uCommerce_Product p
LEFT JOIN uCommerce_PriceGroupPrice pgp ON p.ProductId = pgp.ProductId
LEFT JOIN uCommerce_Product pp ON p.ParentProductId = pp.ProductId
WHERE
p.ParentProductId IS NOT NULL
@timgaunt
timgaunt / EnableDisable.sql
Last active May 9, 2016 23:30
Enable/Disable products without prices
BEGIN TRAN
-- Activate variants
UPDATE uCommerce_Product SET DisplayOnSite = 1, AllowOrdering = 1 where ParentProductId IS NOT NULL
-- Insert the price group prices
INSERT into uCommerce_PriceGroupPrice (ProductId, Price, PriceGroupId)
SELECT p.ProductId, NULL, pg.PriceGroupId
FROM uCommerce_Product p LEFT JOIN uCommerce_PriceGroupPrice pgp ON p.ProductId = pgp.ProductId, uCommerce_PriceGroup pg
WHERE pgp.ProductId IS NULL AND pg.Deleted = 0
$ago = 7;
$now = Get-Date;
$limit = $now.AddDays($ago * -1)
$filename = "UmbracoTraceLog.txt.*"
$path = "D:\Websites\"
# Delete files older than the $limit.
Get-ChildItem -Path $path -Recurse -Force | Where-Object { !$_.PSIsContainer -and $_.LastwriteTime -lt $limit -and $_.name -like $filename } | Remove-Item -WhatIf
# Delete any empty directories left behind after deleting the old files.
@timgaunt
timgaunt / Create Umbraco Database.sql
Created October 28, 2015 16:08
Create an umbraco database -just replace "DATABASENAME" with your database name
USE Master
GO
CREATE DATABASE DATABASENAMECMS
GO
DECLARE @DatabaseName nvarchar(255), @Username nvarchar(255), @Password nvarchar(255), @AddToASPNet bit, @IsUmbracoInstall bit
SET @DatabaseName = 'DATABASENAMECMS' -- NOTE this must also match the CREATE value above and below the "Creating Users" script
SET @Username = 'DATABASENAMEUser'
SET @Password = ''