Tips Maybe You Need


Git

Git Document

https://www.git-scm.com/book/zh/v2

当本地误删除了某文件时

Undo操作

check out

push & pull

auto complete

merge

git init & git remote

git rm

git log

git show

git diff

SSH keys

SSH key 可以让你在你的电脑和Code服务器之间建立安全的加密连接。 先执行以下语句来判断是否已经存在本地公钥:

NuGet

proxy setting

pack package

打包并上传一个.csproj的Nuget包分四步(在.csproj文件目录下进行)

pack files

一般来讲,若上传的Package依赖使用方的一些配置文件(如app.config且只应该包含仅需的部分,在Install Package时若文件已存在会自动合并)则需要将文件名后追加.transform(如app.config.transform),然后在.nuspec文件中添加对应files节点(注意:是直接在节点下):

VS Code

switch project

debug

Atom

github 推荐的新一代IDE

Atom 的可定制化程度非常之高,因为它本身实际上是运行在本地的一个 html (打开 Atom ,按下Command-alt-i即可查看元素)网页, 你可以随意的更改一些style class来调整 IDE 的样式,有2个主要的命令必须记住:

自定义的样式

通过Command-shift-p -> Open Your Stylesheet可以打开style.less文件进行编辑(以我本地为例):



  @TreeViewFontFamily:  Arial !important; // Arial
@TreeViewFontSize: 15px !important;
@TreeViewStatusModifiedColor:  rgba(233, 28, 83, 0.9);//rgb(177, 68, 58);
@TreeViewColor:  rgba(103, 103, 96, 0.93);
@TreeViewSelectedFolderItemsColor:   rgba(255, 255, 255, 0.81);
@TreeViewAddedFileColor: #8BC34A !important;
@TreeViewAddedFileSelectedColor: black !important;
@TreeViewFileIconColor: inherit;

@RecentProjectBackgroundColor: rgba(236, 15, 227, 0.66);
@RecentProjectColor: white;
@RecentProjectFontFamily: fantasy;

@EditorFontFamily:  fantasy !important; // "Helvetica Neue"
@EditorFontSize: 14px !important;
@TransparentColor: transparent;
@TransparentImportantColor: transparent !important;
@KeyOfObjectOrJsxElementColor: orange;
@CursorColor: yellow;
@LineNumberColor: red;
@CurrentLineNumberColor: rgb(236, 17, 161);
@TerminalColor: orange;
@MethodColor: rgb(82, 192, 233);
@ImportedVariableColor: #ccc;
@KeywordColor: rgba(236, 72, 131, 0.9);
@LanguageKeywordColor: rgba(236, 72, 131, 0.9);
@ObjectVariableColor: #ccc;
@ObjectPropertyColor: #ccc;
@PureStringColor: rgba(254, 254, 254, 0.47);
@OperatorColor: orange;
@MethodCallColor: rgba(235, 75, 171, 1);
@MethodDefineColor: orange;

atom-text-editor {
  background-color: @TransparentColor;
  font-family:  @EditorFontFamily;
  font-size: @EditorFontSize;
}

atom-text-editor .cursor {
  border-color: @CursorColor;
}

.amu-panel-contrast .tree-view {
  background-color: @TransparentColor;
}

atom-text-editor .gutter {
  background-color: @TransparentImportantColor;
  color: @LineNumberColor;
}

atom-text-editor .gutter .line-number.cursor-line {
  color: @CurrentLineNumberColor;
}

.platformio-ide-terminal .xterm {
  color: @TerminalColor;
  ::selection {
    background-color: ;
  }

  .terminal-cursor {
    background-color: ;
  }
}

.recent-projects-view .project-list li.project-entry {
  background-color: @RecentProjectBackgroundColor;
  color: @RecentProjectColor;
  font-family: @RecentProjectFontFamily;
}

.syntax--entity.syntax--name.syntax--function {
  color: @MethodColor;
}

.syntax--variable.syntax--other.syntax--module.syntax--js {
  color: @ImportedVariableColor;
}

.syntax--keyword.syntax--control.syntax--js {
  color: @KeywordColor;
}

.syntax--variable.syntax--language.syntax--js {
  color: @LanguageKeywordColor;
}

.syntax--variable.syntax--other.syntax--object.syntax--js {
  color: @ObjectVariableColor;
}

.syntax--variable.syntax--other.syntax--property.syntax--js {
  color: @ObjectPropertyColor;
}

.syntax--string.syntax--quoted.syntax--single.syntax--js {
  color: @PureStringColor;
}

.syntax--string.syntax--quoted.syntax--double.syntax--js {
  color: @PureStringColor;
}

.syntax--source.syntax--js {
  color: @KeyOfObjectOrJsxElementColor;
}

.syntax--keyword.syntax--operator.syntax--comparison.syntax--js {
  color:  @OperatorColor;
}

.syntax--storage.syntax--type.syntax--const.syntax--js {
color: @KeywordColor;
}

.tree-view{
    .list-group li:not(.list-nested-item).status-modified, .list-tree li:not(.list-nested-item).status-modified,
    .list-group li.list-nested-item.status-modified > .list-item, .list-tree li.list-nested-item.status-modified > .list-item {
      color: @TreeViewStatusModifiedColor;
      .medium-yellow:before {
        color: @TreeViewFileIconColor;
      }

      .medium-orange:before {
      color: @TreeViewFileIconColor;
      }
    }

    .list-group li:not(.list-nested-item), .list-tree li:not(.list-nested-item), .list-group li.list-nested-item > .list-item,
    .list-tree li.list-nested-item > .list-item {
      color: @TreeViewColor;
      font-family: @TreeViewFontFamily;
      font-size: @TreeViewFontSize;
    }

    li.selected.expanded {
          .list-group li:not(.list-nested-item), .list-tree li:not(.list-nested-item), .list-group li.list-nested-item > .list-item,
          .list-tree li.list-nested-item > .list-item {
            color: @TreeViewSelectedFolderItemsColor;
          }

          .list-group li:not(.list-nested-item).status-modified, .list-tree li:not(.list-nested-item).status-modified, .list-group
          li.list-nested-item.status-modified > .list-item, .list-tree li.list-nested-item.status-modified > .list-item {
            color: @TreeViewStatusModifiedColor;
            .medium-yellow:before {
              color: @TreeViewFileIconColor;
            }

            .medium-orange:before {
            color: @TreeViewFileIconColor;
            }
          }
      }

      .list-group li:not(.list-nested-item).status-added, .list-tree li:not(.list-nested-item).status-added, .list-group li.list-nested-item.status-added > .list-item, .list-tree li.list-nested-item.status-added > .list-item {
        color: @TreeViewAddedFileColor;
        .medium-yellow:before {
          color: @TreeViewFileIconColor;
        }

        .medium-orange:before {
        color: @TreeViewFileIconColor;
        }
      }
}

:focus .list-group
 li:not(.list-nested-item).selected.status-added,
:focus .list-tree li:not(.list-nested-item).selected.status-added,
:focus .list-group li.list-nested-item.selected > .list-item.status-added,
:focus .list-tree li.list-nested-item.selected > .list-item.status-added {
   color: @TreeViewAddedFileSelectedColor;
 }

 .syntax--meta.syntax--method-call, .syntax--meta.syntax--method {
   color: @MethodCallColor;
 }

.syntax--round {
  color: @MethodDefineColor ;
}

.syntax--punctuation.syntax--definition.syntax--parameters, .syntax--punctuation.syntax--definition.syntax--array {
  color: @MethodDefineColor;
}

.syntax--storage.syntax--modifier.syntax--js {
  color: @KeywordColor;
}

.syntax--storage.syntax--type.syntax--class.syntax--js {
  color: @KeywordColor;
}
  
  

.NET

End abstract/virtual

C#中的sealed关键字有两种用途

WCF FaultException VS Exception

MDI Form

RESTful API

Service Stack

See also:Service Stack Product Docs

SQL Server

嵌套事务快速模板


DECLARE @TranCounter INT;
SET @TranCounter = @@TRANCOUNT;
IF @TranCounter > 0
    SAVE TRANSACTION ProcedureSave;
ELSE
    BEGIN TRANSACTION;
BEGIN TRY

-- your code here


IF @TranCounter = 0
        COMMIT TRANSACTION;
END TRY
BEGIN CATCH
IF @TranCounter = 0
        ROLLBACK TRANSACTION;
    ELSE
        IF XACT_STATE() <> -1
            ROLLBACK TRANSACTION ProcedureSave;
    DECLARE @ErrorMessage NVARCHAR(4000);
    DECLARE @ErrorSeverity INT;
    DECLARE @ErrorState INT;

    SELECT @ErrorMessage = ERROR_MESSAGE();
    SELECT @ErrorSeverity = ERROR_SEVERITY();
    SELECT @ErrorState = ERROR_STATE();

    RAISERROR (@ErrorMessage, -- Message text.
               @ErrorSeverity, -- Severity.
               @ErrorState -- State.
               );
END CATCH
		

创建表对象


USE dbname
GO
/*================================================================================
Server:    ?
DataBase:  ?
Author:    ?
Object:    ?
Version:   1.0
Date:      ??/??/????
Content:   ?
----------------------------------------------------------------------------------
Modified history:

Date        Modified by    VER    Description
------------------------------------------------------------
??/??/????  ??			   1.0    Create.
================================================================================*/

/* Policies by DBA Team
	--BYDBA 1 不建议使用联合主键,而是用自增列配合"创建唯一约束"或"创建唯一索引"
	--BYDBA 1.主键规范命名为:PK_表名或PK_表名_主键字段名
	--BYDBA 1 xml/varhcar(max)/nvarchar(max)这三种类型的列,DBA 建议存储在独立的表中,否则会产生很大的性能问题
	--BYDBA 1 char类型字段,需要预估是否包含多国字符,如果是,请使用nchar
	--BYDBA 1 Money类型是不允许使用的,请用Decimal(12,2)代替
*/

CREATE Table [dbo].[Table]
(
	TransactionNumber		INT IDENTITY(1,1)	NOT NULL,
	Field1					NCHAR(10)			NOT NULL,
	Field2  				NCHAR(3)			NOT NULL CONSTRAINT DF_Table_Field2 DEFAULT ('USA'),--no forget to define the constraint name of default
	Field3					INT					NOT NULL CONSTRAINT DF_Table_Field3 DEFAULT (1),
	Field4					INT					NOT NULL,
	CONSTRAINT [PK_Table] PRIMARY KEY CLUSTERED --Also can be 'PK_Table_TransactionNumber'
	(
		TransactionNumber ASC
	)
) ON [PRIMARY]
GO

--How to create standard nonclustered index
--创建普通索引
CREATE NONCLUSTERED INDEX IX_Table_Field1 ON dbo.Table
(
	[Field1]
)WITH (FILLFACTOR = 90)
Go

--How to create unique index
--创建唯一索引
CREATE UNIQUE NONCLUSTERED INDEX [IXU_Table_Code1_Code2] ON dbo.[Table]
(
	[Code1],[Code2]
)WITH (FILLFACTOR=80) ON [PRIMARY]

		

创建表值函数


USE [Warehouse]
GO

SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE FUNCTION [dbo].[FN_FunctionName] (
    @Param1 varchar(100),
    @Param2 varchar(100)
    ) RETURNS @ResultTable table (Name varchar(100))
AS
BEGIN
    INSERT INTO @ResultTable (Name) VALUES (@Param1 + @Param2)
    RETURN
END

GO


--select Name from Warehouse.dbo.[FN_FunctionName]('Hello','World!')
		

创建单值函数


USE [Warehouse]
GO

SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE FUNCTION [dbo].[FN_FunctionName1](
    @Param1 varchar(15),
    @Param2 varchar(15)
) RETURNS VARCHAR(100)
AS BEGIN

    RETURN @Param1 + @Param2
END
GO

--DECLARE @result VARCHAR(100)
--SET @result = Warehouse.dbo.[FN_FunctionName1]('AB','CD')
--SELECT @result AS Result

--select Warehouse.dbo.[FN_FunctionName1]('AB','CD')
		

创建存储过程


USE dbname
Go
/*================================================================================
Server:    ?
DataBase:  ?
Team:	   ?
Author:    ?
Object:    ?
Version:   1.0
Date:      ??/??/????
Content:   ?
----------------------------------------------------------------------------------
Modified history:

Date        Modified by    VER    Description
------------------------------------------------------------
??/??/????  ??			   1.0    Create.
================================================================================*/

CREATE PROCEDURE [dbo].[UP_YourProcName]
	@Parameter   INT
AS
SET NOCOUNT ON
--Put your code in here




-- usage
-- EXEC dbname.dbo.UP_YourProcName 123,...
		

创建视图


USE dbname
Go
/*================================================================================
Server:    ?
DataBase:  ?
Team:	   ?
Author:    ?
Object:    ?
Version:   1.0
Date:      ??/??/????
Content:   ?
----------------------------------------------------------------------------------
Modified history:

Date        Modified by    VER    Description
------------------------------------------------------------
??/??/????  ??			   1.0    Create.
================================================================================*/

CREATE VIEW [dbo].[UV_EC_ViewNeweggItemsBase_Endeca_V1] AS
--Put your code here
		

普通XML查询语法


/*
	BYDBA 1 解析XML时获取单一值时,不要使用nodes()
	DECLARE @xml xml
	SET @xml = N'<b>text1
				   <c>text2
					  <d>text3
						 <e>text4</e>
					  </d>
					  <f>text5</f>
				   </c>
			  </b>'

	SELECT
        @xml.value('(/b/c/d/text())[1]','char(5)')
       ,@xml.value('(/b/c/f/text())[1]','char(5)')
*/



/*About namespace 命名空间
	DECLARE @xml xml
	SET @xml = N'<b xmlns="https://soa.newegg.com/dba">text1
					 <c>text2
					   <d xmlns="https://soa.neweg.com">text3
						   <e>text4</e>
					   </d>
					   <f>text5</f>
					 </c>
				   </b>'

	;WITH xmlnamespaces(DEFAULT 'https://soa.newegg.com/dba'
								,'https://soa.neweg.com' AS ns)

	SELECT
		@xml.value('(/b/c/text())[1]','char(5)') AS xml_col_val
	   ,@xml.value('(/b/c/ns:d/text())[1]','char(5)') AS xml_col_va2
*/



/*retrieve value 取单个值
	DECLARE @xml xml
	SET @xml = N'<b>text1
					   <c>text2
						  <d>text3
							 <e>text4</e>
						  </d>
						  <f>text5</f>
					   </c>
				   </b>'
	SELECT @xml.value('(/b/c/text())[1]','char(5)') AS xml_col_val
*/
		

定义游标


/*
	定义游标时,如果不是特别需要,使用LOCAL关键显式的将游标定义为局部游标,
	尽量避免使用全局(GLOBAL,这是数据库的默认行为)游标;没有特殊需要的话,
	尽量使用FORWARD_ONLY READ_ONLY STATIC游标,
	--For example:*/
    DECLARE your_cursor CURSOR
        LOCAL
        STATIC
        FORWARD_ONLY
        READ_ONLY
    FOR
		SELECT …

	OPEN your_cursor
    FETCH NEXT FROM cur INTO @your_variable
    WHILE @@fetch_status = 0
      BEGIN
	--Put your code here to use @your_variable

		FETCH NEXT FROM cur INTO @your_variable
      END
	CLOSE your_cursor
	DEALLOCATE your_cursor
		

循环删除、更新


DECLARE
    @rows int,
    @rows_limit int,
    @row_batch int,
    @row_count int
;

SELECT
    @rows = 0,
    @rows_limit = 50000, -- 处理的最大记录数限制
    @row_batch = 1000,       -- 每批处理的记录数
    @row_count = @row_batch
;

WHILE @row_count = @row_batch
    AND @rows < @rows_limit
BEGIN;
/*------operation statement------
	--DELETE
    DELETE TOP(@row_batch) SRC
    FROM source_table SRC       -- 源表
    WHERE yourcondition = 1		-- 记录处理条件

	--UPDATE
    UPDATE TOP(@row_batch) SRC
		SET SRC.field='
    FROM source_table SRC       -- 源表
    WHERE SRC.field is NULL		-- 记录处理条件
---------operation statement-----*/

    SELECT
       @row_count = @@ROWCOUNT,
       @rows = @rows + @row_count
    ;

    WAITFOR DELAY '00:00:10';   -- 每批处理之间的延时
END;

		

删除插入


DELETE TOP(100)
FROM dbo.xxxLog OUTPUT
   ,DELETED.[LogName]
   ,DELETED.[LogType]
   ,DELETED.[InDate]
   ,DELETED.[InUser]
   ,DELETED.[LastEditDate]
   ,DELETED.[LastEditUser]
INTO dbo.yyyLog
WHERE
	InDate < GETDATE()-7
		

有趣的命令行工具

curl

在命令行中用来发起http请求。可以附加header,parameter等等。

curl http://www.baidu.com
		

curl https://www.baidu.com --insecure // 忽略SSL严格验证
		

// 使用Basic Http验证方式(username:password)的可以把在POSTMan中添加
// Http Basic验证之后,可以在header中拿到加密后的Authorization
curl https://www.baidu.com --insecure --header "Authorization=
Basic asXSdsasdIHJKDksjG="
		

pup

在命令行中用来对html做DOM文档元素筛选和查找。我觉得非常有趣的一点是它可以把DOM结构转换成JSON对象,这就大大方便了对DOM元素的访问。

参考:https://github.com/ericchiang/pup

jq

在命令行中对JSON对象进行操作和数据提取。

参考:https://github.com/stedolan/jq & https://stedolan.github.io/jq/

显然,如果你在做一些网络爬虫的小玩意儿,我想是时候采用一些有趣的技术了,比如上边的 curl+pup+jq。
例如你可以在命令行中用“|”做分隔以传递结果依次处理:


curl https://www.baidu.com --insecure |
pup 'div#ftConw json{}' | jq '.[0].children[1].text'

// 结果:
{
  "children": [
    {
      "href": "http://www.baidu.com/duty/",
      "tag": "a",
      "text": "使用百度前必读"
    },
    {
      "class": "cp-feedback",
      "href": "http://jianyi.baidu.com/",
      "tag": "a",
      "text": "意见反馈"
    },
    {
      "src": "//www.baidu.com/img/gs.gif",
      "tag": "img"
    }
  ],
  "id": "cp",
  "tag": "p",
  "text": "©2017 Baidu 京ICP证030173号"
}

curl https://www.baidu.com --insecure |
pup 'div#ftConw json{}' | jq '.[0].children[1].text'

//结果:
"©2017 Baidu 京ICP证030173号“
		

同时,你也可以把结果写入文件:


curl https://www.baidu.com --insecure |
pup 'div#ftConw json{}' | jq '.[0].children[1].text' > data.json
		

node es6 - npm link - modular develop

See Alsohttps://github.com/denghejun/node-es6-modular-design/blob/master/README.MD

(打赏)

If you want to pay for this
I will list your account name here.
HA HA!