Skip to content

Instantly share code, notes, and snippets.

View timgaunt's full-sized avatar

Tim Gaunt timgaunt

View GitHub Profile
@timgaunt
timgaunt / gist:f67acfe1a1c91152c607
Last active August 29, 2015 14:01
Delete Umbraco nodes by DocumentType
BEGIN TRAN
DECLARE @Nodes TABLE (NodeId int)
INSERT INTO @Nodes (NodeId)
SELECT top 1000 n.id
FROM cmsContent C
INNER JOIN cmsContentType CT ON C.contentType = CT.nodeId
INNER JOIN umbracoNode N ON C.nodeId = N.id
WHERE CT.alias = '[Your Document Type Alias Here]'
DECLARE @S varchar(max) = ''
SELECT @S = @S + '
' + [YourField] FROM [YourTable]
SELECT @S AS [Data] FOR XML PATH('')
@timgaunt
timgaunt / gist:0ed5555c460563d3f0fb
Created August 9, 2014 12:03
Set culture in uCommerce
// Set for any request
System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.CreateSpecificCulture("en-US");
// Set only if within Umbraco editor
if (Request.RawUrl.Contains("macroResultWrapper") || Request.RawUrl.Contains("GetMacroResultAsHtmlForEditor"))
{
System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.CreateSpecificCulture("en-US");
}
@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
@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: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: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: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: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: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"