Skip to content

Instantly share code, notes, and snippets.

@alanwei43
alanwei43 / PrettyHosts.csx
Last active May 18, 2019 06:32
Pretty Hosts
#!/usr/bin/env dotnet-script
using System.Runtime.CompilerServices;
using System.IO;
using System.Text.RegularExpressions;
public static string GetScriptFolder([CallerFilePath] string path = null) => Path.GetDirectoryName(path);
static readonly var HOST_PATH = Environment.OSVersion.Platform == PlatformID.Unix ? "/etc/hosts" : @"C:\Windows\System32\drivers\etc\hosts";
public static async Task<IDictionary<String, List<String>>> GetPrettyHosts()
@alanwei43
alanwei43 / JavaScript Iterator.md
Last active May 13, 2019 05:38
JavaScript 迭代器
function* createGenerator() {
    let first = yield 1;
    let second = yield first + 2;
    yield second + 3;
}
let iterator = createGenerator();

iterator.next(); // { value: 1, done: false}
iterator.next(4);// { value: 6, done: false}
@alanwei43
alanwei43 / getAllPropertyNames.md
Created May 8, 2019 14:31
获取对象的所有属性(包括原型链上的)

获取对象的所有属性(包括原型链上的)

function getAllPropertyNames(obj) {
    const props = [];
    do {
        if (obj === Object.prototype)
            break;
        Object.getOwnPropertyNames(obj).forEach(prop => {
 if (!props.includes(prop)) {
@alanwei43
alanwei43 / tidy.hosts.js
Created February 13, 2019 06:11
tidy hosts content
#!/usr/bin/env node
const hostsFilePath = "/etc/hosts";
const fs = require("fs");
const path = require("path");
fs.readFile(hostsFilePath, (err, data) => {
let lines = data.toString().split("\n");
console.log("lines: " + lines.length);
let hosts = lines.map(line => line.replace(/\s+/g, " "))
@alanwei43
alanwei43 / GlobalWebApiExceptionFilter.cs
Created July 9, 2018 09:29
ASP.Net Web API 全局异常捕获
public class GlobalWebApiExceptionFilter : ExceptionFilterAttribute
{
public override void OnException(HttpActionExecutedContext context)
{
base.OnException(context);
if (context.Exception is NotImplementedException)
{
context.Response = new System.Net.Http.HttpResponseMessage(System.Net.HttpStatusCode.OK);
context.Response.Content = new System.Net.Http.StringContent("not implement");
}
@alanwei43
alanwei43 / GlobalErrorActionFilter.cs
Last active July 9, 2018 09:01
ASP.Net 全局异常处理
public class GlobalErrorActionFilter : IExceptionFilter
{
public void OnException(ExceptionContext filterContext)
{
Exception ex = filterContext.Exception;
filterContext.ExceptionHandled = true;
var response = filterContext.HttpContext.Response;
response.Clear();
response.StatusCode = 200;
@alanwei43
alanwei43 / OpenWithSublimeText3.bat
Created July 9, 2018 01:48 — forked from jackielii/OpenWithSublimeText3.bat
Add "Open with Sublime Text 3" to Windows Explorer Context Menu (including folders)
@echo off
SET st2Path=C:\Program Files\Sublime Text 3\sublime_text.exe
rem add it for all file types
@reg add "HKEY_CLASSES_ROOT\*\shell\Open with Sublime Text 3" /t REG_SZ /v "" /d "Open with Sublime Text 3" /f
@reg add "HKEY_CLASSES_ROOT\*\shell\Open with Sublime Text 3" /t REG_EXPAND_SZ /v "Icon" /d "%st2Path%,0" /f
@reg add "HKEY_CLASSES_ROOT\*\shell\Open with Sublime Text 3\command" /t REG_SZ /v "" /d "%st2Path% \"%%1\"" /f
rem add it for folders
@reg add "HKEY_CLASSES_ROOT\Folder\shell\Open with Sublime Text 3" /t REG_SZ /v "" /d "Open with Sublime Text 3" /f
using System;
using System.Collections;
using System.Net;
using System.Net.Security;
using System.Net.Sockets;
using System.Security.Authentication;
using System.Text;
using System.Security.Cryptography.X509Certificates;
using System.IO;
using System;
using System.Text;
using System.IO;
using System.Net;
using System.Net.Sockets;
public class GetSocket
{
private static Socket ConnectSocket(string server, int port)
{
//TODO
/**
* filter
* map
* skip
* take
* aggregate
* sum
* order