Skip to content

Instantly share code, notes, and snippets.

View alantsai's full-sized avatar

Alan Tsai alantsai

View GitHub Profile
@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 / 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 -->
  
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 / ReadMe.md
Created February 19, 2016 09:20
Print Table Column name detail with description. Sql列出DB裡面所有欄位資訊(包含描述欄位) #sql
@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 / Umbraco-Index-ReaMe.md
Last active January 13, 2016 04:15
Umbraco see which table need index #umbraco #sql
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
{
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");
}
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());
@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);