Skip to content

Instantly share code, notes, and snippets.

View stilllisisi's full-sized avatar
🎯
Focusing

stilllisisi

🎯
Focusing
View GitHub Profile
@stilllisisi
stilllisisi / imagehandle.cs
Created February 18, 2020 04:23
【C#-图像处理】图片处理示例(裁剪,缩放,清晰度,水印),基于.Net Framework类库完成
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
namespace WuJian.Common
{
@stilllisisi
stilllisisi / delegateDemo.cs
Last active February 18, 2020 07:20
【C#-委托】从简单的例子理解委托:小金收客户的钱,然后代表客户去向不同的人Say I love you,支持中英文,并可扩展其他语言。
//在.Net中不但可以像C语言一样将函数作为参数传递,并且.Net提供了类型安全机制和更加强大的功能,如下提供了使用委托的完整代码示例:
//增加语言,只需扩展LoveChinese 函数即可!
using System;
namespace DelegateDemo
{
//定义委托
public delegate void LoveDelegate(string name);
public class LoveManager
@stilllisisi
stilllisisi / Tcompare.cs
Created February 18, 2020 08:05
【C#-泛型】从简单的例子理解泛型:有家影视公司选拔偶像派男主角,导演说了,男演员身高是王道,女演员苗条是王道。往后还要选男配角,选女配角,选群众.....
//使用泛型改造Compare类。
//这段代码在优雅度上完胜非泛型,并且可重用性大大提升,可以说它支持所有类型的比较,只要这个类型实现了IComparable接口,同时一劳永逸,不再需要在方法内部作任何扩展。
public class Compare<T> where T : IComparable
{
public T WhoIsBetter(T t1, T t2)
{
if (t1.CompareTo(t2) > 0)
{
return t1;
}
@stilllisisi
stilllisisi / demo.proto
Created February 18, 2020 08:18
【C#-网络通信】Google Protocol Buffers 之.Net应用:Java为服务端,.Net为客户端,Socket通信,使用Protobuf进行数据封装和传输
message MyRequest { //客户端的请求
required int32 version =1; //版本号
required string name =2; //姓名
optional string website =3[default="http://www.paotiao.com/"]; //个人网站
optional bytes data =4; //附加数据
}
message MyResponse { //服务端的响应
required int32 version =1; //版本号
required int32 result =2; //响应结果
@stilllisisi
stilllisisi / barChart.cs
Created February 18, 2020 08:24
【C#-图形化界面】Aspx折线图、柱状图示例(Web Chart)
//颜色数组
privatestring[] myColor =newstring[]
{
"Fuchsia",
"Black",
"Gold",
"Blue",
"HotPink",
"Orange",
"Peru",
@stilllisisi
stilllisisi / FanInFanOut.go
Created February 18, 2020 09:02
【GO-并发/多线程】管道pipeline并发模式:Fan-out 和 Fan-in模式案例
package pipelineDemos
import (
"fmt"
"sync"
"time"
)
// Multiple functions can read from the same channel until that channel is closed; this is called fan-out.
//
@stilllisisi
stilllisisi / 文件按行读取.go
Last active March 13, 2020 09:57 — forked from ma6174/文件按行读取.go
【GO-文件/目录处理】文件按行读取
f, err := os.Open("a.txt")
defer f.Close()
if nil == err {
buff := bufio.NewReader(f)
for {
line, err := buff.ReadString('\n')
if err != nil || io.EOF == err{
break
}
fmt.Println(line)
@stilllisisi
stilllisisi / 使用HTML模板生成字符串.go
Created February 19, 2020 07:33
【GO-网络通信】HTTTP Response代码片段
//////文件:templates/layout.html
<html>
<head>
<title>{ { template "title" . } } </title>
</head>
<body
{ { template "content" . } }
</body>
</html>
@stilllisisi
stilllisisi / assertTest.go
Created February 19, 2020 07:37
【GO-调试】Assert测试断言
type testing_TBHelper interface {
Helper()
}
func Assert(tb testing.TB, condition bool, args ...interface{}) {
if x, ok := tb.(testing_TBHelper); ok {
x.Helper() // Go1.9+
}
if !condition {
if msg := fmt.Sprint(args...); msg != "" {
@stilllisisi
stilllisisi / mainNotOut.go
Created February 19, 2020 07:40
【GO-异常处理】禁止 main 函数退出的方法
func main() {
defer func() { for {} }()
}
func main() {
defer func() { select {} }()
}
func main() {
defer func() { <-make(chan bool) }()