Skip to content

Instantly share code, notes, and snippets.

View dmitshur's full-sized avatar

Dmitri Shuralyov dmitshur

View GitHub Profile
@dmitshur
dmitshur / gist:5f9e93c38f6b75421060
Last active August 28, 2017 19:23
Trying to do reverse range in html/template... Is there a better way?
<ul>
{{/* So simple... */}}
{{range .Commits}}<li>{{.Commit.Message}}</li>
{{end}}
{{/* Is this really the shortest/best way to to do reverse range? */}}
{{range $i, $v := .Commits}}<li>{{(index $.Commits (revIndex $i (len $.Commits))).Commit.Message}}</li>
{{end}}
</ul>
@dmitshur
dmitshur / gist:81f1e59bb0db7febff94
Last active August 29, 2015 14:01
Fastest way to go get -u, and how godep handles revisions that don't exist.

go get

  • Benchmark three ways to get/update (from scratch) the same 17 Go packages contained in a single git repo.
go get -d -u github.com/shurcooL/go/cmd/gocd
go get -d -u github.com/shurcooL/go/cmd/table
go get -d -u github.com/shurcooL/go/exp/11
go get -d -u github.com/shurcooL/go/exp/12
@dmitshur
dmitshur / gist:8486205
Last active January 3, 2016 15:59
Patch to make godoc server display unexported symbols and work on commands. This may be useful for packages you're actively developing and want to see private API of. Modified package is "github.com/golang/gddo/doc".
diff --git a/doc/builder.go b/doc/builder.go
index f772f54..c3b2203 100644
--- a/doc/builder.go
+++ b/doc/builder.go
@@ -560,6 +560,7 @@ func newPackage(dir *gosrc.Directory) (*Package, error) {
if pkg.ImportPath == "builtin" {
mode |= doc.AllDecls
}
+ mode = doc.AllDecls | doc.AllMethods
@dmitshur
dmitshur / story_of_my_life.go
Created January 13, 2014 08:13
Story of my life, in a for loop...
for {
var hmmWhyNotDoItLikeThis Idea = myself.GetNextIdea()
software := hmmWhyNotDoItLikeThis.UnderlyingSoftware()
if software.IsOpenSource() || software.OwnerCompany().DoesEmploy(myself) {
ideaStatus, understanding = hmmWhyNotDoItLikeThis.Evaluate(software.GetSourceCode())
if ideaStatus == GoodIdea ||
(ideaStatus == BadIdea && understanding != nil) {
package main
import "github.com/sergi/go-diff/diffmatchpatch"
import "bytes"
import "os"
import "os/exec"
import "io/ioutil"
func diff_native(s1, s2 string) string {
@dmitshur
dmitshur / gist:7346402
Last active July 13, 2017 18:44
GoSublime setup steps.
@dmitshur
dmitshur / gist:6927554
Last active September 17, 2023 07:35
[Legacy GOPATH mode] How to `go get` private repos using SSH key auth instead of password auth.

WARNING: This gist was created in 2013 and targets the legacy GOPATH mode. If you're reading this in 2021 or later, you're likely better served by reading https://tip.golang.org/cmd/go/#hdr-Configuration_for_downloading_non_public_code and https://golang.org/ref/mod#private-modules.

$ ssh -A vm
$ git config --global url."git@github.com:".insteadOf "https://github.com/"
$ cat ~/.gitconfig
[url "git@github.com:"]
	insteadOf = https://github.com/
$ go get github.com/private/repo && echo Success!
Success!
@dmitshur
dmitshur / gist:30a39a79e7db8c343911
Last active December 19, 2015 02:09 — forked from dinedal/gist:a4a95a871846d4e68937
Benchmark of two Go funcs template.
package main
import "fmt"
import "testing"
import "math/rand"
import "time"
var result bool
func StrCmp(n string) bool {
x := 0
y := func2(func1(x, 5))
y = func3(y)
0 =: x
((x, 5)func1)func2 =: y
(y)func3 = y
0 x
x,5 func1 func2 y
@dmitshur
dmitshur / self-rep.cpp
Created August 15, 2012 19:56
A quine.
#include <iostream>
#include <sstream>
void print(std::stringstream & s, std::string line)
{
std::cout << line << std::endl;
std::string::size_type n = 0;
while (std::string::npos != (n = line.find("\\", n)))
{