Skip to content

Instantly share code, notes, and snippets.

View songzheng45's full-sized avatar

Robin Song songzheng45

  • Beijing
View GitHub Profile
@songzheng45
songzheng45 / MySql-select-into.txt
Created July 20, 2017 06:40
MySql-批量插入数据
1.INSERT INTO SELECT语句
语法:
Insert into Table2(field1,field2,...) select value1,value2,... from Table1
要求目标表 Table2 必须存在,由于目标表 Table2 已经存在,所以我们除了插入源表 Table1 的字段外,还可以插入常量。示例如下:
INSERT INTO collector_cols (collector_id, account_level_id)
SELECT 14, NAME FROM collector_cols WHERE collector_id = ;
@songzheng45
songzheng45 / DisbleQuickEditMode.cs
Last active July 17, 2017 09:34
C#-禁用控制台鼠标点击阻塞程序的功能(禁用快速编辑)
const int STD_INPUT_HANDLE = -10;
const uint ENABLE_QUICK_EDIT_MODE = 0x0040;
[DllImport("kernel32.dll", SetLastError = true)]
internal static extern IntPtr GetStdHandle(int hConsoleHandle);
[DllImport("kernel32.dll", SetLastError = true)]
internal static extern bool GetConsoleMode(IntPtr hConsoleHandle, out uint mode);
[DllImport("kernel32.dll", SetLastError = true)]
internal static extern bool SetConsoleMode(IntPtr hConsoleHandle, uint mode);
@songzheng45
songzheng45 / JavaScript-open-page-on-new-tab.js
Created July 8, 2017 01:32
Javascript-在新标签页打开页面
// 给新窗口七个名字叫"winName", 调用代码时如果tab页已存在,则将切换过去,并刷新页面
var win = window.open('http://abc.com', 'winName');
@songzheng45
songzheng45 / javascript-replace-all-line-breaks-with-br.js
Created July 7, 2017 02:43
Javascript-把所有的换行符替换为<br/>
str = str.replace(/(?:\r\n|\r|\n)/g, '<br />');
@songzheng45
songzheng45 / textarea-enter-and-ctrl-enter-behavior.js
Created July 4, 2017 01:45
JavaScript-在 textarea 中实现 ENTER提交,ctrl+ENTER 换行
$("#message").keydown(function (e) {
if ((e.which === 13 && e.ctrlKey)) {
$(this).val(function (i, val) {
return val + "\n";
});
}
}).keypress(function (e) {
if (e.which === 13 && !e.ctrlKey) {
$('#btnSendMessage').click();
e.preventDefault();
@songzheng45
songzheng45 / C#-generate-random-number-with-guid.cs
Created June 24, 2017 09:36
C#-将Guid作为种子生成随机数
/// <summary>
/// 将Guid作为种子生成随机数(同一个Guid生成相同的随机数)
/// </summary>
/// <param name="min">范围最小值</param>
/// <param name="max">范围最大值</param>
/// <param name="seedGuid">作为种子的Guid值</param>
/// <returns>生成的随机数</returns>
public static int GetRandomNumber(int min, int max, Guid seedGuid)
{
byte[] buffer = seedGuid.ToByteArray();
@songzheng45
songzheng45 / HttpClient-download-file.cs
Created June 15, 2017 02:23
C#-HttpClient 下载文件
using System;
using System.Configuration;
using System.Diagnostics;
using System.IO;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace SevenStarCollect.Update
@songzheng45
songzheng45 / asp-net-get-mappath.cs
Last active June 7, 2017 02:45
ASP.NET-MapPath-获取虚拟路径的实际磁盘路径
// ASP.NET WebForm,ASP.NET MVC
var sPath = Server.MapPath("/FilePath/");
// ASP.NET WebAPI
// 当 WebAPI 寄宿在非IIS下时(如自寄宿),无法访问HttpContext类,因此要调用这个方法来获取虚拟路径的实际磁盘路径
var sPath = System.Web.Hosting.HostingEnvironment.MapPath("/FilePath/");
@songzheng45
songzheng45 / wpf-closing-a-wpf-window-using-mvvm-and-minimal-code-behind.cs
Created May 16, 2017 02:42
wpf:使用MVVM和最少的后置代码关闭一个窗口
//ViewModel
public class BindViewModel : NotificationObject
{
public Action CloseAction = null;
/// <summary>
/// 退出
/// </summary>
public ICommand CloseCommand => new DelegateCommand(() =>
{
@songzheng45
songzheng45 / wpf-Use-DataContext-as-CommandParameter.xaml
Created May 16, 2017 02:38
wpf-将DataContext作为CommandParameter
<Button
x:Name="btnMain"
Command="infra:ApplicationCommands.MyCommand"
CommandParameter="{Binding}"
/>