Skip to content

Instantly share code, notes, and snippets.

View timgaunt's full-sized avatar

Tim Gaunt timgaunt

View GitHub Profile
@timgaunt
timgaunt / Strip extension in Powershell.ps1
Created August 31, 2015 16:31
Strip extension in Powershell
Get-ChildItem "C:\Users\Tim\Desktop\DL\uCommerce\8e0acd5c-f842-49db-933d-cc9e61fcff51\bin" -Filter *.dll.* | `
Foreach-Object{
Rename-Item $_.FullName ([io.fileinfo]$_.FullName).basename
}
@timgaunt
timgaunt / gist:fab448bf6a889904f02a
Created August 14, 2015 06:47
Delete files after a number of days
forfiles -p "< Path To Folder >" -s -m *.* /D -< Number of days ago > /C "cmd /c del @path"
@timgaunt
timgaunt / Content.sql
Created July 27, 2015 18:46
Export Umbraco data in pivot/crosstab table
DECLARE @cols NVARCHAR(max), @ContentTypeId int
SET @ContentTypeId = 1074
SELECT @cols = STUFF((
SELECT DISTINCT TOP 100 PERCENT
'],['
+ CONVERT(varchar, Name + ' (' + CONVERT(varchar, id) + ')', 255)
FROM
dbo.cmsPropertyType
WHERE
@timgaunt
timgaunt / Pre v8.sql
Last active March 10, 2021 09:45
Delete umbraco content via SQL
/* Delete Old Document Versions */
Declare @keepOldVersionsCount int, @keepNewerThanDate datetime
Set @keepOldVersionsCount = 0 /* 0 Keeps published and newest only. */
Set @keepNewerThanDate = getdate() /* getDate() or '2013-01-01' */
IF OBJECT_ID('tempdb..#versions') IS NOT NULL DROP TABLE #versions
SELECT VersionID, nodeId, updateDate, newest, published INTO #versions
@timgaunt
timgaunt / gist:4aeae724a57ae934c60f
Created April 11, 2015 08:06
SQLs new paging/offest
FROM [TableX]
ORDER BY [FieldX]
OFFSET 501 ROWS
FETCH NEXT 100 ROWS ONLY
@timgaunt
timgaunt / gist:564e6543045c50d90103
Created March 25, 2015 10:23
Find voucher code in uCommerce
SELECT TOP 100
*
FROM
uCommerce_CampaignItem ci
LEFT JOIN uCommerce_Target t ON ci.CampaignItemId = t.CampaignItemId
LEFT JOIN uCommerce_VoucherTarget vt ON t.TargetId = vt.VoucherTargetId
LEFT JOIN uCommerce_ProductTarget pt ON t.TargetId = pt.ProductTargetId
WHERE
ci.Name = 'Campaign Item Name'
@timgaunt
timgaunt / gist:10613e3a095525155ca7
Created March 24, 2015 19:43
Make web request gzip'd
HttpWebRequest request = WebRequest.Create(i_Uri) as HttpWebRequest;
request.Headers.Add(HttpRequestHeader.AcceptEncoding, "gzip,deflate");
response = request.GetResponse() as HttpWebResponse;
If(response.Headers.ToString().IndexOf("gzip") != -1)
{
//unzip;
}
private static void DecompressGzipStream(Stream i_GzipStream)
@timgaunt
timgaunt / gist:8e0a78af164d74a61599
Created January 17, 2015 15:29
Split First and Last name from Name
var names = name.Trim().Split(new[] { ' ' }, 2);
string firstName;
string lastName;
if (names.Length == 1)
{
firstName = String.Empty;
lastName = names[0];
}
else
@timgaunt
timgaunt / gist:532aa01b410d13b2b32e
Created January 13, 2015 12:36
foreach loop with count
var enumerateMe = originalList.Select((item, index) => new { Position = index, Item = item });
@timgaunt
timgaunt / gist:c4b04e52b2b1eb6f715c
Created December 12, 2014 13:24
List all websites from PowerShell
get-website | select name,id,state,physicalpath,
@{n="Bindings"; e= { ($_.bindings | select -expa collection) -join ';' }} ,
@{n="LogFile";e={ $_.logfile | select -expa directory}},
@{n="attributes"; e={($_.attributes | % { $_.name + "=" + $_.value }) -join ';' }} |
Export-Csv -NoTypeInformation -Path d:\my_list.csv