This file contains hidden or 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
use itertools::Itertools; | |
use plotlib::page::Page; | |
use plotlib::repr::Plot; | |
use plotlib::style::{LineStyle, PointMarker, PointStyle}; | |
use plotlib::view::ContinuousView; | |
fn main() { | |
let p: f64 = 0.5; | |
let q = 1. - p; | |
let n = 20; |
This file contains hidden or 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 "fmt" | |
var colorRed = string([]byte{27, 91, 57, 55, 59, 51, 49, 59, 49, 109}) | |
var colorReset = string([]byte{27, 91, 48, 109}) | |
func main() { | |
fmt.Printf("%s messag%s normal\n", colorRed, colorReset) | |
} |
This file contains hidden or 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
func (b *builder) Build() error { | |
args := append([]string{"go", "build", "-o", filepath.Join(b.wd, b.binary)}, b.buildArgs...) | |
var command *exec.Cmd | |
if b.useGodep { | |
args = append([]string{"godep"}, args...) | |
} | |
command = exec.Command(args[0], args[1:]...) | |
command.Dir = b.dir |
This file contains hidden or 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
# containerは存在しない | |
docker container ls -a | |
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES | |
# 起動 | |
go run main.go | |
2017-11-23T02:30:38.881+0900 INFO workspace/main.go:52 local_docker_db {"status": "starting"} | |
2017-11-23T02:30:38.934+0900 DEBUG workspace/main.go:77 local_docker_db {"container_info": "not_found", "container": "myproject-mysql-db"} | |
2017-11-23T02:30:39.428+0900 DEBUG workspace/main.go:107 local_docker_db {"exec docker cmd": "docker container run --detach --name myproject-mysql-db --publish 3307:3306 --mount type=bind,source=/tmp/docker_db,target=/var/lib/mysql --env MYSQL_USER=gopher --env MYSQL_PASSWORD=golangorgohome --env MYSQL_INITDB_SKIP_TZINFO=yes --env MYSQL_ALLOW_EMPTY_PASSWORD=yes mysql:5.6", "stdout": "4a7336c9364b14df0813463161335d8690d9c6e777f5c631bb406b5f55d2e181\n", "stderr": ""} |
This file contains hidden or 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
func game(change bool) int { | |
choice := rand.Intn(3) | |
prize := rand.Intn(3) | |
if change { | |
var opened int | |
for { | |
opened = rand.Intn(3) | |
if opened != prize && opened != choice { | |
break |
This file contains hidden or 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 ( | |
"bufio" | |
"fmt" | |
"os" | |
"strings" | |
"time" | |
"golang.org/x/net/context" |
This file contains hidden or 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 safebuffer | |
import ( | |
"bytes" | |
"sync" | |
) | |
// Buffer is a goroutine safe bytes.Buffer | |
type Buffer struct { | |
buffer bytes.Buffer |
This file contains hidden or 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 safebuffer | |
import ( | |
"bytes" | |
"sync" | |
) | |
// Buffer is a goroutine safe bytes.Buffer | |
type Buffer struct { | |
buffer bytes.Buffer |
This file contains hidden or 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
if _, err := os.Stat("/path/to/whatever"); os.IsNotExist(err) { | |
// path/to/whatever does not exist | |
} | |
if _, err := os.Stat("/path/to/whatever"); err == nil { | |
// path/to/whatever exists | |
} |
This file contains hidden or 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 ( | |
"flag" | |
"fmt" | |
"os" | |
) | |
func main() { | |
askCommand := flag.NewFlagSet("ask", flag.ExitOnError) |
NewerOlder