Skip to content

Instantly share code, notes, and snippets.

Ivan Zezyulya ivanzoid

Block or report user

Report or block ivanzoid

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
View Golang shabang.go
//usr/bin/env go run $0 -- "$@"; exit $?
View Golang write string to file.go
package main
import "os"
func writeStringToFile(path string, s string) error {
file, err := os.Create(path)
if err != nil {
return err
}
View Golang make directory if not exists.go
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
}
View Bash script template with arguments.sh
#!/bin/bash -ex
usage()
{
local PROG_NAME=`basename $0`
echo "Usage: $PROG_NAME params"
}
main()
{
View Bash program exists.sh
program_exists () {
type "$1" &> /dev/null ;
}
if ! program_exists foo; then
echo "Please install foo"
exit 2
fi
View Bash compare strings.sh
# 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
View gist-update.go
//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
View Golang run command.go
package main
import (
"os/exec"
"strings"
"fmt"
)
func runProgram1(program string, args ...string) (string, error) {
outStrings, err := runProgram(program, args...)
View Golang read first string from file.go
package main
import (
"os"
"bufio"
)
func readFirstLineFromFile(path string) (string, error) {
file, err := os.Open(path)
if err != nil {
You can’t perform that action at this time.