Skip to content

Instantly share code, notes, and snippets.

@gobwas
gobwas / iface_test.go
Last active October 3, 2017 16:19
Alloc-free interface usage
// This example shows how interfaces could be used without
// pushing inner data to heap.
//
// Note that it was checked with Go 1.8.3 and may become unuseful
// in the future releases of Go.
package main
import (
"encoding/binary"
"testing"
@simonw
simonw / how-to.md
Last active March 26, 2024 23:21
How to create a tarball of a git repository using "git archive"
@karablin
karablin / defer.rs
Last active January 2, 2021 02:10
go-like defer for rust
#[feature(macro_rules)];
struct ScopeCall<'cls> {
c: 'cls ||
}
#[unsafe_destructor]
impl<'cls> Drop for ScopeCall<'cls> {
fn drop(&mut self) {
(self.c)();
}
@hgfischer
hgfischer / benchmark+go+nginx.md
Last active April 11, 2024 22:09
Benchmarking Nginx with Go

Benchmarking Nginx with Go

There are a lot of ways to serve a Go HTTP application. The best choices depend on each use case. Currently nginx looks to be the standard web server for every new project even though there are other great web servers as well. However, how much is the overhead of serving a Go application behind an nginx server? Do we need some nginx features (vhosts, load balancing, cache, etc) or can you serve directly from Go? If you need nginx, what is the fastest connection mechanism? This are the kind of questions I'm intended to answer here. The purpose of this benchmark is not to tell that Go is faster or slower than nginx. That would be stupid.

So, these are the different settings we are going to compare:

  • Go HTTP standalone (as the control group)
  • Nginx proxy to Go HTTP
  • Nginx fastcgi to Go TCP FastCGI
  • Nginx fastcgi to Go Unix Socket FastCGI
@hofmannsven
hofmannsven / README.md
Last active May 3, 2024 15:30
Git CLI Cheatsheet
@creationix
creationix / output.log
Created May 8, 2013 22:02
Working version of generator async code sample. Using node from https://github.com/andywingo/node/tree/v8-3.19
tim@touchsmart:~/Code$ nvm use v0.11.2-generators
Now using node v0.11.2-generators
tim@touchsmart:~/Code$ node --harmony testgen.js
<Buffer 76 61 72 20 66 73 20 3d 20 72 65 71 75 69 72 65 28 27 66 73 27 29 3b 0a 66 75 6e 63 74 69 6f 6e 20 72 65 61 64 46 69 6c 65 28 70 61 74 68 2c 20 65 6e 63 ...>
Sleeping for 2000ms...
Done
@icholy
icholy / go_zsh_complete.md
Last active January 9, 2022 19:19
Zsh Tab Completion for Golang

Zsh Tab Completion for Golang

This is pretty specific to my setup but the idea can be adapted to work with pretty much anything.

Go has a flag package which makes parsing command line arguments really easy.

package main
package systemd
import (
"os"
"strconv"
"syscall"
)
const (
listenFdsStart = 3
@mattratleph
mattratleph / vimdiff.md
Last active April 24, 2024 11:28 — forked from roothybrid7/vimdiff_cheet.md
vimdiff cheat sheet

vimdiff cheat sheet

##git mergetool

In the middle file (future merged file), you can navigate between conflicts with ]c and [c.

Choose which version you want to keep with :diffget //2 or :diffget //3 (the //2 and //3 are unique identifiers for the target/master copy and the merge/branch copy file names).

:diffupdate (to remove leftover spacing issues)

:only (once you’re done reviewing all conflicts, this shows only the middle/merged file)

@MohamedAlaa
MohamedAlaa / tmux-cheatsheet.markdown
Last active May 3, 2024 19:09
tmux shortcuts & cheatsheet

tmux shortcuts & cheatsheet

start new:

tmux

start new with session name:

tmux new -s myname