Skip to content

Instantly share code, notes, and snippets.

View toashd's full-sized avatar
🧃

Tobias Schmid toashd

🧃
  • Munich · Berlin
View GitHub Profile
@toashd
toashd / latency.txt
Created September 2, 2020 15:20 — forked from jboner/latency.txt
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers (~2012)
----------------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns 3 us
Send 1K bytes over 1 Gbps network 10,000 ns 10 us
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD
@toashd
toashd / gist:c0c3918cac81f8feec399e1159ef099e
Created September 25, 2018 18:01
Dokku – Running out of space with many deployments.
# check space
df -h
# delete all non-running container
docker ps -a | grep 'Exit' | awk '{print $1}' | xargs docker rm
# delete unused images
docker images | grep '<none>' | awk '{print $3}' | xargs docker rmi
# delete specific images
@toashd
toashd / fff.sh
Created March 17, 2018 18:27
Find first folder name that contains a string
find <dir> -maxdepth 1 -type d -name '*foo*' -print -quit
@toashd
toashd / imgfmt.go
Created March 30, 2016 13:00
Determine image file format in golang.
// imageFormat returns the image format.
func imageFormat(file *os.File) string {
bytes := make([]byte, 4)
n, _ := file.ReadAt(bytes, 0)
file.Seek(0, 0)
if n < 4 {
return ""
}
if bytes[0] == 0x89 && bytes[1] == 0x50 && bytes[2] == 0x4E && bytes[3] == 0x47 {
return "png"
@toashd
toashd / main.go
Created December 29, 2015 14:53
Golang array vs. slice
package main
import (
"fmt"
"reflect"
)
func main() {
var i = [...]uint8{0, 7, 16, 22, 28} // array, compiler counts elements
@toashd
toashd / main.go
Created October 17, 2015 09:42
Go generator example
package main
import (
"fmt"
"time"
)
type generator struct {
generateNext chan struct{}
sendCh chan int
@toashd
toashd / update_fork.sh
Last active October 14, 2015 10:52
Git snippet to update a forked repository
# Add the remote, call it "upstream":
git remote add upstream https://github.com/whoever/whatever.git
# Fetch all the branches of that remote into remote-tracking branches,
# such as upstream/master:
git fetch upstream
# Make sure that you're on your master branch:
@toashd
toashd / export-gh-issues.sh
Created August 24, 2015 13:35
Export github issues to json
curl -u ':uname' 'https://api.github.com/repos/:org/:repo/issues' > issues.json
@toashd
toashd / transnav.swift
Created April 18, 2015 18:46
Transparent nav bar
self.navigationController?.navigationBar.setBackgroundImage(UIImage(), forBarMetrics: UIBarMetrics.Default)
self.navigationController?.navigationBar.shadowImage = UIImage()
self.navigationController?.navigationBar.translucent = true
@toashd
toashd / gist:6c0f918f8c86bceae89a
Created March 12, 2015 14:19
Switch postgres version with brew
$ brew tap homebrew/versions
$ brew install postgresql92
$ brew switch postgresql 9.2.8