Skip to content

Instantly share code, notes, and snippets.

@yang-qu
yang-qu / fetch-git-remote-changes.txt
Created February 17, 2017 00:29
fetch git remote changes and remove branches not existed on remotes
git fetch --prune
@yang-qu
yang-qu / db_size.sql
Created December 5, 2016 03:13
get sql server db size
SELECT
database_name = DB_NAME(database_id)
, log_size_mb = CAST(SUM(CASE WHEN type_desc = 'LOG' THEN size END) * 8. / 1024 AS DECIMAL(8,2))
, row_size_mb = CAST(SUM(CASE WHEN type_desc = 'ROWS' THEN size END) * 8. / 1024 AS DECIMAL(8,2))
, total_size_mb = CAST(SUM(size) * 8. / 1024 AS DECIMAL(8,2))
FROM sys.master_files WITH(NOWAIT)
--WHERE database_id = DB_ID() -- for current db
GROUP BY database_id
-- get a list of stored procedures
select * from sys.procedures
-- get sproc parameters names
SELECT name
FROM sys.parameters
WHERE object_id = OBJECT_ID('sproc name')
-- get sproc parameters name, type, and length
SELECT p.name AS ParameterName, t.name AS ParameterType, p.max_length AS ParameterLength
FROM sys.parameters AS p
JOIN sys.types AS t ON t.user_type_id = p.user_type_id
@yang-qu
yang-qu / git_push_local_branch.txt
Created October 6, 2016 06:56
Git push local branch to remote and track it
#Git push local branch to remote and track it
git push -u origin <branch>
@yang-qu
yang-qu / GitPrune.txt
Created September 27, 2016 00:20
Synce Git Changes
#execute this after remotes branches have been deleted.
git fetch --all --prune
@yang-qu
yang-qu / archive_git_changed_files.txt
Created August 24, 2016 06:42
Archive changed files between two commits in a git repository
# Get changed(added or modified) files list to a text file.
git diff --name-only --diff-filter=AM <commit1>..<commit2> > changes.txt
# Create 7z archive. On windows git bash, this can also deal with file names with spaces.
7z a changes.7z -ir@"changes.txt"
@yang-qu
yang-qu / _vimrc
Created August 4, 2014 00:00
vimrc_windows
set clipboard=unnamed
set guifont=Consolas:h12:cANSI
syntax on
colorscheme github
@yang-qu
yang-qu / _vsvimrc
Last active August 29, 2015 14:04
vsvimrc
set backspace=indent,eol,start
set vsvim_useeditordefaults
set clipboard=unnamed
@yang-qu
yang-qu / table_size.sql
Last active June 30, 2017 01:07
get tables size in sql server 2008 ~ 2014
--size in KB
SELECT
s.Name AS SchemaName,
t.NAME AS TableName,
p.rows AS RowCounts,
SUM(a.total_pages) * 8 AS TotalSpaceKB,
SUM(a.used_pages) * 8 AS UsedSpaceKB,
(SUM(a.total_pages) - SUM(a.used_pages)) * 8 AS UnusedSpaceKB
FROM
sys.tables t
@yang-qu
yang-qu / LINQDistinctBy.cs
Last active August 29, 2015 14:01
LINQ DistinctBy
using System;
using System.Collections.Generic;
using System.Linq;
public static class LINQExtension
{
public static IEnumerable<TSource> DistinctBy<TSource, TKey>
(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector)
{
HashSet<TKey> knownKeys = new HashSet<TKey>();