Skip to content

Instantly share code, notes, and snippets.

Dmitri Shuralyov dmitshur

Block or report user

Report or block dmitshur

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@dmitshur
dmitshur / main.go
Last active Sep 12, 2019
A simple server for HTTPS and HTTP protocols.
View main.go
// A simple server for HTTPS and HTTP protocols. It implements these behaviors:
//
// • uses Let's Encrypt to acquire and automatically refresh HTTPS certificates
//
// • redirects HTTPS requests to canonical hosts, reverse proxies requests to internal backing servers
//
// • redirects all HTTP requests to HTTPS
//
// • gates certain endpoints with basic auth, using bcrypt-hashed passwords
//
View main.go
package main
import (
_ "fmt"
_ "net"
_ "github.com/samuel/go-zookeeper"
_ "github.com/mocktesting/nolongerexists"
)
@dmitshur
dmitshur / main.go
Last active Jan 28, 2018
Server for HTTPS protocol. Redirects to canonical hosts, reverse proxies requests to internal backing servers.
View main.go
// Server for HTTPS protocol. Redirects to canonical hosts, reverse proxies requests to internal backing servers.
package main
import (
"crypto/tls"
"flag"
"log"
"net/http"
"net/http/httputil"
"time"
@dmitshur
dmitshur / main.go
Last active Sep 6, 2017
Server for HTTP protocol. Redirects all requests to HTTPS.
View main.go
// Server for HTTP protocol. Redirects all requests to HTTPS.
package main
import (
"flag"
"log"
"net/http"
)
var (
@dmitshur
dmitshur / Default (OSX).sublime-keymap
Created Nov 17, 2014
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.
View Default (OSX).sublime-keymap
[
// ... (existing content)
// Add folder that contains current file to sidebar.
{ "keys": ["f3"], "command": "add_to_project" },
// ...
]
@dmitshur
dmitshur / Default (OSX).sublime-keymap
Last active Aug 29, 2015
Sublime Text on OS X, make Cmd+F do the equivalent of Cmd+E followed by Cmd+F. Works for all selections, not just single line like "find_selected_text" setting.
View Default (OSX).sublime-keymap
[
// ... (existing content)
// Find selected text, even if it spans multiple lines (unlike "find_selected_text").
{ "keys": ["super+f"], "command": "run_multiple_commands", "args":
{ "commands":
[
// Only execute slurp if there's selected text.
{"command": "slurp_find_string", "context": "window", "condition": "selected_text"},
{"command": "show_panel", "args": {"panel": "find", "reverse": false}, "context": "window"}
@dmitshur
dmitshur / gist:86949a392dcdac1f94cf
Last active Sep 12, 2016
The experience of compiling Go and C++ projects.
View gist:86949a392dcdac1f94cf

Compiling a Go project.

Conception-go $ go install
Conception-go $ 

Compiling a C++ project.

View gist:3f58c38dc262058c3e04

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:5f9e93c38f6b75421060
Last active Aug 28, 2017
Trying to do reverse range in html/template... Is there a better way?
View gist:5f9e93c38f6b75421060
<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>
You can’t perform that action at this time.