Skip to content

Instantly share code, notes, and snippets.

package bench_append_test
import (
"testing"
)
const N = 10
func BenchmarkBareAppend(bench *testing.B) {
var values = make([]int, N)
@ninedraft
ninedraft / update_macro.rs
Last active January 21, 2019 19:14
update! macro for liquid-style 'updating'
macro_rules! update {
(&$data:ident, $( $key:ident = $x:expr ),*) => (
{
fn clone<T>(data: &T) -> T
where T: Clone {
data.clone()
}
let cp = clone(&$data);
update!(cp, $( $key = $x ),*)
}
func NewHTTPClient() *http.Client {
return &http.Client{
Timeout: 10 * time.Second,
Transport: &http.Transport{
DialContext: (&net.Dialer{
Timeout: 5 * time.Second,
}).DialContext,
TLSHandshakeTimeout: 5 * time.Second,
},
}
@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
@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 / 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 / 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 / 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 / .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 / 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