Skip to content

Instantly share code, notes, and snippets.

View alantsai's full-sized avatar

Alan Tsai alantsai

View GitHub Profile
@alantsai
alantsai / ps-setFileLastWriteTime.ps1
Last active November 24, 2015 09:54
Set specific LastWriteTime (Modified Time) of a directory child file. 把資料夾下面檔案的最後修改時間改成特定時間. #powershell
# 日期格式是 dd/MM/yyyy HH:mm
dir -file -recurse | % { $_.LastWriteTime = '11/19/2015 14:20' }
@alantsai
alantsai / ps-displayAllFileWithLastWriteTime.ps1
Last active November 24, 2015 10:00
display all files under directory with LastWriteTime (Last Modify Time) and full file path order by LastWriteTime. 取得目前資料夾的所有檔案的最後修改時間和檔案路徑的Table,依照最後修改時間排序. #powershell
# inspire from https://rcmtech.wordpress.com/2010/08/12/powershell-find-files-modified-after-a-certain-date/
dir -File -recurse | Sort-object LastWriteTime -desc | format-table lastwritetime, fullname -autosize
# 匯出到檔案 files.txt
dir -File -recurse | Sort-object LastWriteTime -desc | format-table lastwritetime, fullname -autosize | out-dir files.txt
SELECT
t.NAME AS TableName,
s.Name AS SchemaName,
p.rows AS RowCounts,
SUM(a.total_pages) * 8 AS TotalSpaceKB,
SUM(a.used_pages) * 8 AS UsedSpaceKB,
(SUM(a.total_pages) - SUM(a.used_pages)) * 8 AS UnusedSpaceKB
FROM
sys.tables t
INNER JOIN
var find = 'abc';
var re = new RegExp(find, 'g');
str = str.replace(re, '');
@alantsai
alantsai / sql-delete-data-history.sql
Created November 29, 2015 17:42
umbraco delete data version last then certain date. 刪除某個日期之前的歷史資料. Source: https://our.umbraco.org/projects/backoffice-extensions/falm-housekeeping/bugs-reports/42409-The-wait-operation-timed-out #umbraco
DECLARE @versionDate date;
SET @versionDate = CONVERT(DATETIME, 11/26/2015, 102); -- delete data older than provide date
SELECT nodeId, published, documentUser, versionId, text, releaseDate, expireDate, updateDate, templateId, newest into #tmp
FROM cmsDocument WHERE versionID NOT IN
(SELECT D.versionId FROM cmsDocument D WHERE D.versionId IN
@alantsai
alantsai / ReadeMe.md
Created December 3, 2015 01:27
Get Current IPublishedContent in Umbraco. 取得目前的IPublishedContent. #umbraco

Source:Get current node as IPublishedContent

var currentNode = UmbracoContext.Current.PublishedContentRequest.PublishedContent;

Or

UmbracoHelper umbracoHelper = new UmbracoHelper(UmbracoContext.Current);
public class Global : HttpApplication
{
public void Application_Start()
{
// Clears all previously registered view engines.
ViewEngines.Engines.Clear();
// Registers our Razor C# specific view engine.
// This can also be registered using dependency injection through the new IDependencyResolver interface.
ViewEngines.Engines.Add(new RazorViewEngine());
public static double WeightedAverage<T>(this IEnumerable<T> records, Func<T, double> value, Func<T, double> weight)
{
double weightedValueSum = records.Sum(x => value(x) * weight(x));
double weightSum = records.Sum(x => weight(x));
if (weightSum != 0)
return weightedValueSum / weightSum;
else
throw new DivideByZeroException("Your message here");
}
using System;
using System.Data.Entity.Core.Objects;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
namespace Fenton.Example
{
public static class IQueryableExtensions
{
@alantsai
alantsai / Umbraco-Index-ReaMe.md
Last active January 13, 2016 04:15
Umbraco see which table need index #umbraco #sql