Skip to content

Instantly share code, notes, and snippets.

@akhuang
akhuang / Async.cs
Created September 6, 2012 04:31 — forked from SamSaffron/Async.cs
Async class for threading
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Threading;
using System.Diagnostics;
using System.Text;
namespace StackOverflow.Helpers
@akhuang
akhuang / SimpleInstaller
Created June 25, 2013 13:12
Simple Installer use Wix toolset 3.8
<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<Product Id="*" Name="SimpleInstaller" Language="1033" Version="1.0.0.0" Manufacturer="MS" UpgradeCode="254afadb-8ed5-48e1-809f-f769cd030828">
<Package InstallerVersion="200" Compressed="yes" InstallScope="perMachine" />
<MajorUpgrade DowngradeErrorMessage="A newer version of [ProductName] is already installed." />
<MediaTemplate />
<Feature Id="ProductFeature" Title="SimpleInstaller" Level="1">
<ComponentGroupRef Id="ProductComponents" />
public static class HtmlExtensions
{
public static MvcHtmlString ValidatedEditorFor<TModel, TProperty>(this HtmlHelper<TModel> htmlHelper, Expression<Func<TModel, TProperty>> expression)
{
if (htmlHelper.ViewData.ModelMetadata.ModelType == null)
{
return new MvcHtmlString(String.Empty);
}
TagBuilder tagBuilder = new TagBuilder("input");
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace MvcApplication1.ViewModels
{
public class ArticleEditViewModel
@akhuang
akhuang / EnumToSelectList
Created August 24, 2013 00:25
Create dropdownlist from an enum
public static SelectList ToSelectList<TEnum>(this TEnum enumObj)
where TEnum : struct, IComparable, IFormattable, IConvertible
{
var values = from TEnum e in Enum.GetValues(typeof(TEnum))
select new { Id = e, Name = e.ToString() };
return new SelectList(values, "Id", "Name", enumObj);
}
@akhuang
akhuang / gist:6657761
Created September 22, 2013 07:53
How to select the first/least/max row per group in SQL
/****** Object: Table [dbo].[Fruit] Script Date: 09/22/2013 15:53:26 ******/
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Fruit]') AND type in (N'U'))
DROP TABLE [dbo].[Fruit]
GO
/****** Object: Table [dbo].[Fruit] Script Date: 09/22/2013 15:53:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Fruit]') AND type in (N'U'))
@akhuang
akhuang / KataFizzBuzz
Created September 23, 2013 00:47
Kata: FizzBuzz
List<int> list=new List<int>();
int i=1;
while(i<=100)
{
list.Add(i);
i++;
}
foreach(int j in list)
{
string s = "adadf(深圳)(em.test@163.net.cn) 是我的email地址";
//it's wrong; when target is "test.test@mail.com, the output is test@mail.com
//string ptn = @"[a-z\d_\-]+@[a-z\d_\-]+(.[a-z\d_\-]+)+";
string ptn=@"\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*";
Regex reg = new Regex(ptn, RegexOptions.IgnoreCase);
Match m = reg.Match(s);
Console.WriteLine(m.ToString());
@akhuang
akhuang / gist:6681488
Created September 24, 2013 07:34
convert column's value to string that join with ','
DataTable table = new DataTable();
table.Columns.Add(new DataColumn("Column #1"));
table.Columns.Add(new DataColumn("Column #2"));
table.Rows.Add(1, 2);
table.Rows.Add(11, 22);
table.Rows.Add(111, 222);
foreach (var column in table.Columns)
{
DataColumn dc = column as DataColumn;
################################################################################################################################
#
# Script Name : SmoDb
# Version : 1.0
# Author : Vince Panuccio
# Purpose :
# This script generates one SQL script per database object including Stored Procedures,Tables,Views,
# User Defined Functions and User Defined Table Types. Useful for versionining a databsae in a CVS.
#
# Usage :