Skip to content

Instantly share code, notes, and snippets.

@iMega
iMega / main.go
Created July 26, 2018 11:13
Утренний затуп
package main
import (
"fmt"
)
type Person struct{
Name string
}
@iMega
iMega / main.go
Created June 1, 2018 09:12
Дублирование потоков
package main
import (
"bytes"
"io"
"io/ioutil"
"log"
"strings"
)
// Copyright 2015 The Cockroach Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
package grpc
import (
"math"
"time"
"github.com/davecgh/go-spew/spew"
"github.com/facebookgo/stack"
"github.com/grpc-ecosystem/go-grpc-middleware"
grpclogrus "github.com/grpc-ecosystem/go-grpc-middleware/logging/logrus"
@iMega
iMega / use-opentracing
Created March 14, 2018 16:13
Как отслеживать все поведение распределенной транзакции?
## 系统执行一条SQL,到底慢在哪里?
如何跟踪一个分布式事务的所有行为?使用 [opentracing](http://opentracing.io/)! opentracing 是一个标准的分布式 tracing 的协议。支持 Go, JavaScript, Java, Python, Ruby, PHP, Objective-C, C++, C# 等等许多的语言(暂时没看到 rust 的库)。
[一些基本的概念](https://github.com/opentracing/specification/blob/master/specification.md#the-opentracing-data-model):一个 Trace 是由许多 Span 构成的一个有向无环图。Span 之间的边的关系叫做 Reference。
Span 里面的信息包括:操作的名字,开始时间和结束时间,可以附带多个 key:value 构成的 Tags(key必须是string,value可以是 string, bool 或者数字),还可以附带 Logs 信息(不一定所有的实现都支持),也是 key:value形式。
下面例子是一个 Trace,里面有8个 Span:
@iMega
iMega / spawn.lua
Created December 22, 2017 09:38 — forked from neomantra/spawn.lua
Using LuaJIT FFI, spawn a Linux command in the background.
-- Spawn a command in the background, optionally redirecting stderr and stdout
--
-- requiring this file returns a function(cmd_line, stdout_redirect, stderr_redirect)
--
-- `cmd_line` is the command with possible arguments
-- optional `stdout_redirect` is io.stdout, io.stderr, or a filename. default/nil is io.stdout
-- optional `stderr_redirect` is io.stdout, io.stderr, or a filename. default/nil is io.stderr
--
-- Example:
-- luajit -e 'require("spawn")("cat /etc/network/interfaces", "foo1", io.stdout)'
func EqualWithDuration(t *testing.T, expected, actual interface{}, delta time.Duration) bool {
a := reflect.ValueOf(actual)
e := reflect.ValueOf(expected)
for i := 0; i < a.NumField(); i++ {
if a.Field(i).Type() == reflect.TypeOf(time.Time{}) {
assert.WithinDuration(t, e.Field(i).Interface().(time.Time), a.Field(i).Interface().(time.Time), delta)
} else {
assert.Equal(t, e.Field(i).Interface(), a.Field(i).Interface())
}
package mail
import "time"
type From []Mailbox
type Sender Mailbox
type ReplyTo []Address
SET @tables = NULL;
SELECT GROUP_CONCAT(table_schema, '.', table_name)
INTO @tables
FROM information_schema.tables
WHERE table_schema = 'ippart';
SET @tables = CONCAT('DROP TABLE ', @tables);
PREPARE stmt FROM @tables;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
```
$ shopt -q login_shell && echo 'Login shell' || echo 'Not login shell'
```