Skip to content

Instantly share code, notes, and snippets.

View alantsai's full-sized avatar

Alan Tsai alantsai

View GitHub Profile
@alantsai
alantsai / Duplicate-Department-Node-Permission.sql
Created January 14, 2016 20:51
Umbraco Department package - Duplicate same department node permission to another department. #umbraco #sql
DECLARE @fromDepartmentId int;
DECLARE @toDepartmentId int;
SET @fromDepartmentId = $fromDepartmentId; -- set 來源copy的單位 - 以我們例子就是單位A
SET @toDepartmentId = $departmentId; -- set 要被copy的單位 - 以我們例子就是單位B
INSERT INTO Department2NodePermission (DepartmentId, NodeId, Permission)
SELECT
@toDepartmentId,
[NodeId],
@alantsai
alantsai / ReadMe.md
Created February 19, 2016 09:20
Print Table Column name detail with description. Sql列出DB裡面所有欄位資訊(包含描述欄位) #sql
var jq = document.createElement('script');
jq.src = "https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js";
document.getElementsByTagName('head')[0].appendChild(jq);
// ... give time for script to load, then type.
jQuery.noConflict();
@alantsai
alantsai / asp.net-website-upload-file-size-limit.md
Created April 11, 2016 01:52
Change asp .net website file upload size to 50MB #asp.net #asp.net-mvc

In the webconfig, add following two:

More Info

<configuration>
  <system.web>
    <!--unit in kb-->
    <!-- default 4096 -> 4MB -->
  
@alantsai
alantsai / 1 Question.md
Last active May 9, 2016 04:21
Check up the inheritance chanin if a class inherit a generic type From http://stackoverflow.com/questions/457676/check-if-a-class-is-derived-from-a-generic-class #csharp

I have a generic class in my project with derived classes.

public class GenericClass<T> : GenericInterface<T>
{
}
public class Test : GenericClass
@alantsai
alantsai / remove-ignore-file-from-track.md
Last active January 11, 2018 19:25
remove all track file which are ignored in the .gitignore - 把git裡面屬於.gitignore檔案被加入版控的檔案從版控刪掉 #git

Sometimes some files are accedntily added into the source control, which later relaized caused by not include a project level .gitignore

Below command provide way to remove all track files which should be ignored

  1. Produce the .gitignore file first and place in the root of git project

  2. Remove all files (-r for recurse, . mean from current directory) from git
    but leave the physical file untouch (indicate by the --cache option)

@alantsai
alantsai / show-index-usage.sql
Last active May 29, 2016 09:01
Find Index Usage of a Database since it start the server - 取得db自啟動來的索引使用量 - #sql
DECLARE @databaseId nvarchar(128);
SET @databaseId = 'dbname'; ---改成要查看的資料庫
-- 用戶索引查找次數 -> 這個表示主動用where條件過濾的欄位
-- 用戶索引被動查找次數 -> 這個表示被動做join的次數
select db_name(database_id) as N'資料庫名稱',
@alantsai
alantsai / get-installed-sql-server-instance.md
Last active December 19, 2016 07:06
Get installed Sql Server Instance - 取得安裝在機器上面的 sql server #powershell

Location of installed sql server Instance

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\Instance Names\SQL

EDIT:

If you are looking for 32 bit instances on a 64 bit OS, you will need to look here:

HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Microsoft SQL Server\Instance Names\SQL

@alantsai
alantsai / setFileTime.ps1
Created January 28, 2017 03:32
Set Timestamp for specific file #powershell
# usage Set-FileTimeStamps -path C:Ref -date 7/1/11
# From https://blogs.technet.microsoft.com/heyscriptingguy/2012/06/01/use-powershell-to-modify-file-access-time-stamps/
Function Set-FileTimeStamps
{
Param (
[Parameter(mandatory=$true)]
@alantsai
alantsai / deleteFilesFromZip.ps1
Created January 30, 2017 14:32
Delete files from zip file using powershell #powershell
# original from http://stackoverflow.com/questions/20269202/remove-files-from-zip-file-with-powershell
# 這邊是從某個zip檔案裡面的對應對應files刪掉
[Reflection.Assembly]::LoadWithPartialName('System.IO.Compression')
$zipfile = 'C:\path\to\your.zip'
$files = 'some.file', 'other.file', ...
$stream = New-Object IO.FileStream($zipfile, [IO.FileMode]::Open)
$mode = [IO.Compression.ZipArchiveMode]::Update