Skip to content

Instantly share code, notes, and snippets.

@hoangitk
hoangitk / create new database.mysql
Last active August 29, 2015 14:05
MySql: Create new database
mysql> CREATE DATABASE newdbname CHARACTER SET utf8;
mysql> CREATE USER 'newdbuser'@'localhost' IDENTIFIED BY 'my_password';
mysql> GRANT ALL PRIVILEGES ON newdbname.* TO 'newdbuser'@'localhost';
mysql> \q
@hoangitk
hoangitk / list all table info.sql
Created September 4, 2014 08:45
How to find largest objects in a SQL Server database?
SELECT
t.NAME AS TableName,
i.name as indexName,
sum(p.rows) as RowCounts,
sum(a.total_pages) as TotalPages,
sum(a.used_pages) as UsedPages,
sum(a.data_pages) as DataPages,
(sum(a.total_pages) * 8) / 1024 as TotalSpaceMB,
(sum(a.used_pages) * 8) / 1024 as UsedSpaceMB,
(sum(a.data_pages) * 8) / 1024 as DataSpaceMB
@hoangitk
hoangitk / query detail from .trc
Created September 4, 2014 08:48
query data from sql profiler trace file
SELECT TextData, Duration/1000/60 [Duration (m)], Reads, Writes, CPU, StartTime
FROM fn_trace_gettable('F:\RestoreDB\HR 4.3.1\TSG01\TSG01_aCao.trc',1)
where 1=1
-- and Duration > 10000 -- over 10s
and textdata is not null
-- and textdata LIKE N'%sp_replcmds%'
order by duration desc
CREATE FUNCTION SplitString
(
@Input NVARCHAR(MAX),
@Character CHAR(1)
)
RETURNS @Output TABLE (
Item NVARCHAR(1000)
)
AS
BEGIN
-- PatternSplitLoop will split a string based on a pattern of the form
-- supported by LIKE and PATINDEX
--
-- Created by: Dwain Camps 11-Oct-2012
CREATE FUNCTION [dbo].[PatternSplitLoop]
( @String VARCHAR(400)
,@Pattern VARCHAR(500)
) RETURNS
@Results TABLE ( ItemNumber INT
this.session.Query<Notice>().Where( n =>
this.session.Query<User>().Any(u => u.UserId == "007"
&& !u.DismissedNotices.Contains(n) );
public static class NhTransformers
{
public static readonly IResultTransformer ExpandoObject;
static NhTransformers()
{
ExpandoObject = new ExpandoObjectResultSetTransformer();
}
private class ExpandoObjectResultSetTransformer : IResultTransformer
using System;
using System.Collections;
using System.Collections.Generic;
using System.Dynamic;
using System.Linq;
using System.Text.RegularExpressions;
using Castle.ActiveRecord;
using Castle.ActiveRecord.Framework.Config;
using log4net.Config;
using NHibernate;
IF OBJECT_ID(‘tempdb..#sometable’) IS NOT NULL
DROP TABLE #sometable
using System;
using System.Security.Cryptography;
public class UniqueIdGenerator
{
private static readonly UniqueIdGenerator _instance = new UniqueIdGenerator();
private static char[] _charMap = { // 0, 1, O, and I omitted intentionally giving 32 (2^5) symbols
'2', '3', '4', '5', '6', '7', '8', '9',
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'J', 'K', 'L', 'M', 'N', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'
};