Skip to content

Instantly share code, notes, and snippets.

View dmitshur's full-sized avatar

Dmitri Shuralyov dmitshur

View GitHub Profile
@dmitshur
dmitshur / gist:86949a392dcdac1f94cf
Last active September 12, 2016 04:31
The experience of compiling Go and C++ projects.

Compiling a Go project.

Conception-go $ go install
Conception-go $ 

Compiling a C++ project.

An example where var err error; something, err = foo() is nicer than something, err := foo().

This is a less common situation.

	fd := os.Stdout
	if *output != "" {
		var err error
		fd, err = os.Create(*output)
 if err != nil {
@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: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)))
{
@dmitshur
dmitshur / MutuallyConnectable.h
Last active October 8, 2015 08:48
When you want classes A and B to be mutually connected to each other, derive them from this class template.
#pragma once
#ifndef __MutuallyConnectable_H__
#define __MutuallyConnectable_H__
// Usage: Suppose you want to have two classes A and B that are mutually connected to each other.
//
// Derive the class A from MutuallyConnectable<A, B> where A is the class you're deriving
// and B is the other class you want to make mutual connections with.
// Derive the class B from MutuallyConnectable<B, A>.
//
@dmitshur
dmitshur / Default (OSX).sublime-keymap
Created November 17, 2014 20:54
Add folder that contains current file to sidebar, for Sublime Text. Goes well with Cmd+.,Cmd+O of GoSublime until https://github.com/DisposaBoy/GoSublime/issues/553 is resolved.
[
// ... (existing content)
// Add folder that contains current file to sidebar.
{ "keys": ["f3"], "command": "add_to_project" },
// ...
]