Example #1
0
func (w *RedisWordlist) Get(count, offset int) ([]string, error) {
	conn := w.conn.Get()
	defer conn.Close()
	starting_offset := math.IntMax(offset, 0)
	ending_offset := math.IntMax((starting_offset+count)-1, 1)
	return redis.Strings(conn.Do("ZRANGE", w.key, starting_offset, ending_offset))
}
Example #2
0
// Ensure that x and y offsets does contain image.
func (im *Image) normalizeOffset(w, h uint, xOffset, yOffset int) (x int, y int) {
	x, y = im.gravity(w, h)
	x += xOffset
	y += yOffset
	x -= math.IntMax(0, x+int(w)-int(im.w))
	y -= math.IntMax(0, y+int(h)-int(im.h))
	return math.IntMax(0, x), math.IntMax(0, y)
}
Example #3
0
func blacklistGet(t *testing.T, count, offset int, out []string) {
	r, err := http.Get(fmt.Sprintf("http://%s/v1/profanity/blacklist/?lang=%s&count=%d&offset=%d", serverAddr, "en_US", count, offset))

	if err != nil {
		t.Fatalf("error getting: %s", err)
		return
	}

	var res blacklistResponse
	err = json.NewDecoder(r.Body).Decode(&res)

	if err != nil {
		t.Fatal(err)
	}

	log.Printf("res: %v", res)
	expLen := math.IntMin(math.IntMax(res.Total-offset, 0), count)

	if len(res.Blacklist) != expLen {
		t.Fatalf("%d != %d", len(res.Blacklist), expLen)
	}

	if out != nil {
		for i := 0; i < len(res.Blacklist); i++ {
			if res.Blacklist[i] != out[i] {
				t.Fatalf("%s != %s", res.Blacklist[i], out[i])
			}
		}
	}
}