Skip to content

Instantly share code, notes, and snippets.

@akhuang
akhuang / gist:4937e8e62efbe07dedd2
Created October 11, 2014 07:40
string.join; ReadOnlyCollection: can't add/remove item, but you can change value
List<string> list=new List<string>();
list.Add("k");
list.Add("b");
Console.WriteLine(string.Join(",",list));
List<Student> listStu= new List<Program.Student>();
listStu.Add(new Student(){ Name="p" });
listStu.Add(new Student(){ Name="p2" });
@akhuang
akhuang / Sql.UpdateSort
Created June 25, 2014 03:40
sql update sort
update DICT_COUNTRIES set Country_Seq=(select count(*) from DICT_COUNTRIES t2 where t2.COUNTRY_ID<=t1.COUNTRY_ID )
from DICT_COUNTRIES t1
@akhuang
akhuang / DeployJekyllWithGit
Last active August 29, 2015 14:02
how deploy jekyll with git
https://www.digitalocean.com/community/tutorials/how-to-deploy-jekyll-blogs-with-git
#yum install git
#curl -L https://get.rvm.io | bash -s stable --ruby=2.0.0
#gem install jekyll
#jekyll new blog
#cd blog
#git init --bare
#cd hooks
#touch post-receive
@akhuang
akhuang / readContent
Created December 9, 2013 01:22
Read all content under the specified folder
using System;
using System.Collections.Generic;
using System.IO;
using System.Collections;
using System.Text;
public class MyClass
{
public static string FOLDERPATH=@"D:\Temp\UpdateScript\";
public static string ExcludeFolder=".svn";
@akhuang
akhuang / gist:7431013
Created November 12, 2013 13:43
Allow passing data arguments to a modal /** URL: https://github.com/twbs/bootstrap/pull/6256
Allows adding custom data as any number of data parameters:
<li><a data-person="Zim" data-toggle="modal" data-target="#person-modal"></a></li>
<li><a data-person="Dib" data-toggle="modal" data-target="#person-modal"></a></li>
...
Use the show event to inject your custom data into the modal.
$('#person-modal').on('show', function (event) {
name = $(this).data('modal').options.person
$(this).find('.person').html(name)
################################################################################################################################
#
# 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 :
@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;
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 / 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)
{
@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'))