Example #1
0
File: qfetch.go Project: mxpang/lab
func main() {
	flag.Parse()

	cfg, err := NewConfig(*FlagCfg)
	if err != nil {
		log.Fatal(err)
	}
	kcfg := &kodo.Config{AccessKey: cfg.AccessKey, SecretKey: cfg.SecretKey}
	cli := kodo.New(cfg.Zone, kcfg)

	bucket := cli.Bucket(*FlagBucket)

	if *FlagList {
		// TODO: more list
		entries, _, err := bucket.List(context.TODO(), "", "", 1000)
		if err != nil {
			log.Fatal(err)
		}
		pretty.Printf("%# v\n", entries)
	}

	if *FlagKey != "" && *FlagUrl != "" {
		err := bucket.Fetch(context.TODO(), *FlagKey, *FlagUrl)
		if err != nil {
			log.Fatal(err)
		}

		entry, err := bucket.Stat(context.TODO(), *FlagKey)
		if err != nil {
			log.Fatal(err)
		}
		pretty.Printf("%# v\n", entry)
	}

}
Example #2
0
// fatal error handler.
func fatal(a assertable, userArgs interface{}, formatString string, formatArgs ...interface{}) {
	if _, file, line, ok := runtime.Caller(3); ok {
		fmt.Printf("\n--- %v:%v\n", file, line)

		if lineString := strings.TrimSpace(getLine(file, line)); lineString != "" {
			fmt.Printf("\t%v\n", lineString)
		}
	}

	fmt.Printf(format(userArgs, formatString, formatArgs...))
	a.FailNow()
}
Example #3
0
func main() {
	var filename string

	flag.StringVar(&filename, "filename", "", "Filename")
	flag.Parse()

	data := parseFile(filename)

	min := bruteForce(data)
	pretty.Printf("%# v\n", min)

	sort.Sort(byX(data))
	min = divideConquer(data)
	pretty.Printf("%# v\n", min)
}
Example #4
0
func logPretty(x interface{}) {
	_, file, line, ok := runtime.Caller(1)
	if !ok {
		file = "???"
		line = 0
	}
	lineNo := strconv.Itoa(line)
	s := file + ":" + lineNo + ": %# v\n"
	pretty.Printf(s, x)
}
Example #5
0
func (self *chainSampler) Map(f func(d interface{})) {
	self.lock.RLock()
	defer self.lock.RUnlock()

	for seqNum, obv := range self.samples {
		if _, ok := obv.(int); !ok {
			pretty.Printf("Seq %v. WAT: %# v\n", seqNum, obv)
		}
		f(obv)
	}
}
Example #6
0
func (b *Birthday) handleOutgoingMessage(msg interface{}) {
	switch m := msg.(type) {
	case *ari.AriConnected:
		fmt.Println("Outgoing: ARI connected")

	case *ari.StasisStart:

		fmt.Println("Outgoing: Statis started, detecting speech")
		m.Channel.SetVar("TALK_DETECT(set)", "500")

		// Bridge with the other folk
		b.mixingBridge.AddChannel(m.Channel.Id, ari.Participant)

	case *ari.StasisEnd:
		fmt.Println("Outgoing: Statis ended")
	case *ari.ChannelDtmfReceived:
		fmt.Println("Outgoing: Got DTMF:", m.Digit)
	case *ari.ChannelTalkingStarted:
		fmt.Println("Outgoing: They started talking!")

	case *ari.ChannelTalkingFinished:
		fmt.Println("Outgoing: They stopped talking! Talked for", m.Duration, "ms")

	case *ari.ChannelDestroyed:
		fmt.Println("Outgoing: Channel destroyed, back to dialing")
		b.stopOutgoingProcessing()
		b.outgoingChannel = nil
		b.incomingChannel.Play(ari.PlayParams{
			Media: "sound:confbridge-has-left",
		})
		b.dtmfControlMode = true

	case *ari.ChannelHangupRequest:
		fmt.Printf("Outgoing: Hangup for channel %s\n", m.Channel)

	case *ari.ChannelVarset:
		//fmt.Printf("Outgoing: Setting channel variable: %s to '%s'\n", m.Variable, m.Value)

	case *ari.PlaybackStarted:
		fmt.Println("Outgoing: Playback started")

	case *ari.ChannelStateChange:
		fmt.Printf("Outgoing: ChannelStateChange: %#v\n", m.Channel)

	case *ari.PlaybackFinished:
		fmt.Println("Outgoing: Playback finished: ", m.Playback.MediaURI)

	default:
		pretty.Printf("Outgoing: Received some message: %+v\n", msg)
	}
}
func main() {
	var roleDir, _ = os.Getwd()
	roleDir += "/roles/"
	fileInfos, err := ioutil.ReadDir(roleDir)

	if err != nil {
		fmt.Errorf("Directory cannot read %s\n", err)
		os.Exit(1)
	}

	var readme = ""
	var readme_filepath = ""
	var defaults_filepath = ""
	sort.Sort(ByName{fileInfos})
	for _, fileInfo := range fileInfos {
		if fileInfo.IsDir() {
			readme = "#" + fileInfo.Name() + "\n\n"
			readme += "## abstruct \n\n"
			readme += "## variables \n\n"
			defaults_filepath = roleDir + fileInfo.Name() + "/defaults/main.yml"

			source, err := ioutil.ReadFile(defaults_filepath)
			if err != nil {
				fmt.Printf("%s\n", defaults_filepath+":file cannot open.")
				continue
			}
			m := make(map[interface{}]interface{})
			err = yaml.Unmarshal(source, &m)
			if err != nil {
				fmt.Printf("%s\n", defaults_filepath+":fail to parse yaml file.")
				continue
			}

			readme += "|variable name|default value|\n|---|---|\n"
			for index, element := range m {
				readme += "|" + fmt.Sprint(index) + "|" + fmt.Sprint(element) + "| \n"
			}
			readme_filepath = roleDir + fileInfo.Name() + "/README.md"
			err = ioutil.WriteFile(readme_filepath, []byte(readme), 0644)
			if err != nil {
				fmt.Printf("%s\n", readme_filepath+":fail to write readme.")
			}
			pretty.Printf("--- m:\n%# v\n\n", m)
		}
	}
}
Example #8
0
// This should be a min heap
func TestESSampleHeap(t *testing.T) {
	h := &esSampleHeap{}
	heap.Init(h)
	min := 5.0
	N := 10

	for i := 0; i < N; i++ {
		key := rand.Float64()
		if key < min {
			min = key
		}
		heap.Push(h, esSampleItem{nil, key})
	}
	l := *h
	if l[0].key != min {
		t.Errorf("not a min heap")
		pretty.Printf("min=%v\nheap=%# v\n", min, l)
	}
}
Example #9
0
func (self *chainSampler) expireAndReplace() {
	expSeqNum := self.numObservations - self.windowSize
	if _, ok := self.samples[expSeqNum]; !ok {
		// No sample expires
		return
	}
	delete(self.samples, expSeqNum)
	// There must be a replacement, otherwise panic.
	replacementSeqNum := self.sampleChain[expSeqNum]
	// The sequence number must increase by one for each observation.
	replacement, ok := self.replacements[replacementSeqNum]
	if !ok {
		log.Printf("cannot find %v. which is the replacement of %v\n", replacementSeqNum, expSeqNum)
		pretty.Printf("chain: %# v\n", self)
		panic("Should never occur!")
	}
	// This observation must have arrived before.
	self.samples[replacementSeqNum] = replacement
}
Example #10
0
func (b *Birthday) handleIncomingMessage(msg interface{}) {
	switch m := msg.(type) {
	case *ari.AriConnected:
		//fmt.Println("Incoming: ARI connected, setting up mixing bridge")
		b.Setup()

	case *ari.StasisStart:
		//fmt.Println("Incoming: Statis started, detecting speech")
		b.incomingChannel = m.Channel

		b.currentPlayback, _ = m.Channel.Play(ari.PlayParams{
			Media: "sound:hello-world",
		})

		b.mixingBridge.AddChannel(m.Channel.Id, ari.Participant)

	case *ari.StasisEnd:
		fmt.Println("Incoming: Statis ended")

	case *ari.ChannelDtmfReceived:
		fmt.Println("Incoming: Got DTMF:", b.dtmfDigits, m.Digit)

		if b.dtmfControlMode {
			if m.Digit == "*" {
				b.hangupOutgoing()
				b.dtmfControlMode = false
			} else if m.Digit == "1" {
				b.playSong()
			} else if m.Digit == "4" {
				b.playAndRecordSong()
			} else if m.Digit == "7" {
				b.recordMessage()
			} else if m.Digit == "#" {
				b.stopOutgoingProcessing()
			}
		} else {
			// Dial mode
			if m.Digit != "#" && m.Digit != "*" {
				b.dtmfDigits = fmt.Sprintf("%s%s", b.dtmfDigits, m.Digit)
			} else if m.Digit == "*" {
				b.dtmfDigits = ""
			} else if m.Digit == "#" {
				// Do the dial, and reset digits
				b.outgoingNumber = b.dtmfDigits
				b.dialOutgoing(b.outgoingNumber)
				b.dtmfDigits = ""
			}
		}

	case *ari.ChannelTalkingStarted:
		//fmt.Println("Incoming: They started talking!")

	case *ari.ChannelTalkingFinished:
		//fmt.Println("Incoming: They stopped talking! Talked for", m.Duration, "ms")

	case *ari.ChannelHangupRequest:
		fmt.Printf("Incoming: Hangup for channel %s\n", m.Channel)
		b.hangupOutgoing()

	case *ari.ChannelVarset:
		//fmt.Printf("Incoming: Setting channel variable: %s to '%s'\n", m.Variable, m.Value)

	case *ari.PlaybackStarted:
		//fmt.Println("Incoming: Playback started")

	case *ari.PlaybackFinished:
		//fmt.Println("Incoming: Playback finished: ", m.Playback.MediaURI)

	default:
		pretty.Printf("Incoming: Received some message: %+v\n", msg)
	}
}
Example #11
0
func TestRecipe(t *testing.T) {
	br := NewRecipe()
	pretty.Printf("%# v\n\n", br.advertisers)
}
Example #12
0
func ppf(format string, a ...interface{}) (int, error) {
	if debug {
		return pretty.Printf(format, a...)
	}
	return 0, nil
}
Example #13
0
func logPretty(x interface{}) {
	_, file, line, _ := runtime.Caller(1)
	lineNo := strconv.Itoa(line)
	s := file + ":" + lineNo + ": %# v\n"
	pretty.Printf(s, x)
}
Example #14
0
func main() {
	var t *T = new(T)
	var t1 T
	pretty.Printf("%v, %v, %d %d", *t, t1, unsafe.Sizeof(t), unsafe.Sizeof(t1))
}
Example #15
0
func write(ev string, c color.Attribute, msg interface{}) {
	cFunc := color.New(c).SprintFunc()
	pretty.Printf("%s: %# v\n", cFunc(ev), msg)
}