This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//usr/bin/env go run $0 -- "$@"; exit $? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import "os" | |
func writeStringToFile(path string, s string) error { | |
file, err := os.Create(path) | |
if err != nil { | |
return err | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import "os" | |
func makeDirectoryIfNotExists(path string) error { | |
if _, err := os.Stat(path); os.IsNotExist(err) { | |
return os.Mkdir(path, os.ModeDir|0755) | |
} | |
return nil | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# Without arguments: | |
# | |
#!/bin/bash -ex | |
main() | |
{ | |
# … | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash -ex | |
usage() | |
{ | |
local PROG_NAME=`basename $0` | |
echo "Usage: $PROG_NAME params" | |
} | |
main() | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
program_exists () { | |
type "$1" &> /dev/null ; | |
} | |
if ! program_exists foo; then | |
echo "Please install foo" | |
exit 2 | |
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Bash compare strings | |
if [ "$x" = "valid" ]; then | |
echo "x has the value 'valid'" | |
fi | |
if [ "$x" != "valid" ]; then | |
echo "x has the value 'valid'" | |
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//usr/bin/env go run $0 -- "$@"; exit $? | |
// | |
// Use this script to maintain a set of github gists as files. | |
// | |
// Usage: | |
// - install 'gist' program (https://github.com/defunkt/gist) | |
// - make sure you have Go (https://golang.org) installed | |
// - make a folder somewhere where you want to store your gists. | |
// - place gist-update.go (https://gist.github.com/ivanzoid/611177bbd3f5cb0604810f07080757b3#file-gist-update-go) to this folder |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"os/exec" | |
"strings" | |
"fmt" | |
) | |
func runProgram1(program string, args ...string) (string, error) { | |
outStrings, err := runProgram(program, args...) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"os" | |
"bufio" | |
) | |
func readFirstLineFromFile(path string) (string, error) { | |
file, err := os.Open(path) | |
if err != nil { |