Skip to content

Instantly share code, notes, and snippets.

View toashd's full-sized avatar
🧃

Tobias Schmid toashd

🧃
  • Munich · Berlin
View GitHub Profile
package main
import (
"bytes"
"fmt"
)
func main() {
var buffer bytes.Buffer
@toashd
toashd / gist:ee105034c763a65c5534
Created January 29, 2015 11:07
Go check if file exists
// Exists reports whether the named file or directory exists.
func Exists(name string) bool {
if _, err := os.Stat(name); err != nil {
if os.IsNotExist(err) {
return false
}
}
return true
}
@toashd
toashd / install_rmagick.sh
Last active August 29, 2015 14:16
Install RMagick linked to some specific ImageMagick version
sudo C_INCLUDE_PATH=/usr/local/Cellar/imagemagick/6.9.0-10/include/ImageMagick-6/wand/ PKG_CONFIG_PATH=/usr/local/Cellar/imagemagick/6.9.0-10/lib/pkgconfig/ gem install rmagick
@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
@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 / 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 / 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 / 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 / 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 / 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"