Skip to content

Instantly share code, notes, and snippets.

type t interface {
Errorf(string, ...interface{})
}
func testStringer(test t, str stringer, expected ...string) {
var value = str.String()
if value == "" {
test.Errorf("%T.String() must not return an empty string", str)
return
package log
import (
"context"
)
type ctxKeyType struct{}
var ctxKey ctxKeyType
@ninedraft
ninedraft / suit_test.go
Last active July 10, 2020 09:18
Golang test suite helper (MIT)
// MIT License
//
// Copyright (c) 2020 Petrukhin Pavel
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
@ninedraft
ninedraft / Dockerfile
Last active June 18, 2020 07:28
Go with generics docker file dev.go2go
FROM golang:1.14 as builder
RUN git clone \
--depth 1 \
--single-branch \
--branch=dev.go2go \
--progress \
https://go.googlesource.com/go /go2
ENV CGO_ENABLED=0
@ninedraft
ninedraft / .golangci.yml
Last active May 18, 2020 09:44
My opinionated golangci-lint config (tool repo https://github.com/golangci/golangci-lint)
run:
# concurrency: 2 # available CPU number
timeout: 5m # timeout for analysis
issues-exit-code: 1 # exit code when issue was found
build-tags: [] # list of build tags
tests: true # include tests
skip-dirs: [] # dirs to skip
skip-dirs-use-default: true # skip vendor, third_party, test_data
modules-download-mode: readonly # readonly|release|vendor
@ninedraft
ninedraft / zap.go
Created March 13, 2020 11:40
go.uber.org/zap logger factory helpers
package log
import (
"io"
"time"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
)
@ninedraft
ninedraft / export_prs.js
Last active February 27, 2020 09:55
Export merge requests from Gitlab page to a formatted text list with links and short descriptions
// ==UserScript==
// @name Export merge requests to a text file
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author You
// @match https://git.kodix.ru/vgr/garage/merge_requests
// @grant none
// ==/UserScript==
@ninedraft
ninedraft / index.js
Created February 14, 2020 11:07
Export list of merge requests from gitlab to text
var query = "//*[contains(concat(' ', normalize-space(@class),' '), 'merge-request-title-text ')]/a";
var formatter = function(elem, i) {
return "review " + elem.innerText + ". Link: " + elem.href
}
var tasks = $x(query)
.map(formatter)
.join('\n');
console.log(tasks);
@ninedraft
ninedraft / test_test.go
Created May 30, 2019 09:34
Unit test skeleton
import (
"errors"
"strings"
"testing"
"github.com/google/go-cmp/cmp"
)
func TestTest(test *testing.T) {
@ninedraft
ninedraft / jupyter_bootstrap.py
Last active April 21, 2019 08:26
jupyter templates
%matplotlib inline
import numpy as np
import scipy.constants as scc
import scipy.integrate as sci
from mpl_toolkits.mplot3d import Axes3D
from matplotlib import pyplot as plt
import scipy.optimize as sco