Skip to content

Instantly share code, notes, and snippets.

@chai2010
chai2010 / main.go
Last active August 29, 2015 14:07
Go模拟显示接口
package main
import (
"fmt"
"testing"
)
func main() {
testTB(new(TB))
}

发现一个针对图像的 泛型+接口 的模式: http://godoc.org/github.com/chai2010/webp#Image

优点:

  • 接口, 可扩展图像格式, 比如 RGB/RGB48
  • 泛型, m.Pix() 返回底层数组结构, 可优化性能
  • 结合, m.Pix() 采用 []byte 类型, 可在运行时混合 RGB/RGB48 不同类型

按照 C++ 的泛型思路, RGB/RGB48 的 m.Pix() 类型应该为 []uint8 和 []uint16, 这样的话 就不能统一到 Go的 interface 类型了.

@chai2010
chai2010 / gist:350df12e19220fdbd014
Created October 17, 2014 05:32
[]T转[]*T类型
// http://play.golang.org/p/068n_JHmQU
package main
import (
"fmt"
"image"
"reflect"
)
@chai2010
chai2010 / grep.c
Created December 4, 2014 04:31
迷你grep实现
/* Copyright (C) 1999 Lucent Technologies */
/* Excerpted from 'The Practice of Programming' */
/* by Brian W. Kernighan and Rob Pike */
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "eprintf.h"
int grep(char*, FILE*, char*);
@chai2010
chai2010 / eprintf.c
Created December 4, 2014 04:32
迷你printf实现
/* Copyright (C) 1999 Lucent Technologies */
/* Excerpted from 'The Practice of Programming' */
/* by Brian W. Kernighan and Rob Pike */
#include <stdio.h>
#include <stdlib.h>
#include "eprintf.h"
#include <stdarg.h>
#include <string.h>
#include <errno.h>
@chai2010
chai2010 / gist:9095218191544251d5f8
Last active August 29, 2015 14:12
Tab和Space的缩进问题
@chai2010
chai2010 / gist:87b36b277209cdf91e22
Last active August 29, 2015 14:13
markdown comment
<!-- This is a comment. -->
[comment]: <> (This is a comment, it will not be included)
[comment]: <> (in  the output file unless you use it in)
[comment]: <> (a reference style link.)

[//]: <> (This is also a comment.)
@chai2010
chai2010 / test.md
Last active August 29, 2015 14:20
x/image/tiff: test

// golang/go#10597 // test

func TestDecodeInvalidDataType(t *testing.T) {
	b, err := ioutil.ReadFile("../testdata/bw-uncompressed.tiff")
	if err != nil {
		t.Fatal(err)
	}
@chai2010
chai2010 / winsvc.go
Created May 12, 2015 05:44
Windows系统服务例子
// Copyright 2015 <chaishushan{AT}gmail.com>. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// +build ingore
package main
import (
"flag"
@chai2010
chai2010 / local.md
Created May 15, 2015 02:37
golangdoc/local 新接口设计
package local

// Default is the translations dir.
const (
	DefaultDir = "translations"     // 默认: $(RootFS)/translations
	DefaultEnv = "GODOC_LOCAL_ROOT" // 优先取环境变量, 支持多个目录
)

// Init initialize the translations environment.