Skip to content

Instantly share code, notes, and snippets.

((function(){
print("creating collection 'textx' and inserting 50 trues, 50 falses, 50 non-existents")
db.testx.drop();
db.testx.ensureIndex({deleted:1});
for (var i=0;i<50;i++){
db.testx.insert({i:i,deleted:false})
};
for (var i=0;i<50;i++){
db.testx.insert({i:i,deleted:true})
};
@tidwall
tidwall / format
Last active August 29, 2015 14:18
C Style Formatting for Swift
func formatv(fstr : String, args : [CVarArgType]) -> String{
var (res, af, i) = ("", "", 0)
for c in fstr {
if af == "" {
if c == "%"{
af = "%"
} else {
res += String(c)
}
} else {
@tidwall
tidwall / goswitch
Last active January 23, 2016 16:13
Switch Go version from command line.
#!/bin/bash
# goswitch is a command line tool for quickly switching Go version.
## Usage
# Switch to go1.6beta1:
# $ goswitch 1.6beta1
# Switch to go1.5.2
# $ goswitch 1.5.2
# List available versions
@tidwall
tidwall / git-status.sh
Last active January 26, 2016 21:12
Simple git status for subdirectories.
#!/bin/bash
set -e
cd $(dirname "${BASH_SOURCE[0]}")
for d in */ ; do
if [ -d "$d/.git" ]; then
cd "$d"
status=$(git status)
n=$(basename "`pwd`");
if [[ $status == *"working directory clean"* ]]; then
printf "%-20s\x1b[32mCLEAN\x1b[0m\n" $n
@tidwall
tidwall / 3000000.sh
Last active May 25, 2016 20:38
Tile38 3,000,000 nearby test
# Pull the latest tile38/master branch.
# Start Tile38 server in dev mode and very verbose.
./tile38-server -dev -vv
# From another terminal run use the CLI to insert 3,000,000 random points around the Silicon Valley area.
# This will create a collection key "mi:0" with points ids "0" - "2999999".
./tile38-cli massinsert 1 3000000 37.10776 -122.67145 38.19502 -121.62775
# Update location for point id "1001".
@tidwall
tidwall / iteration_test.go
Created May 31, 2016 02:10
google/btree iteration benchmark
package btree
import (
"sort"
"testing"
)
type byInts []Item
func (a byInts) Len() int {
@tidwall
tidwall / main.go
Last active July 8, 2016 12:15
Tile38 + Redigo
package main
import (
"flag"
"fmt"
"log"
"time"
"github.com/garyburd/redigo/redis"
)
@tidwall
tidwall / WebSocket.swift
Created July 26, 2016 23:55
import Compression
/*
* SwiftWebSocket (websocket.swift)
*
* Copyright (C) Josh Baker. All Rights Reserved.
* Contact: @tidwall, joshbaker77@gmail.com
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
*
*/
package gjson
import (
"encoding/json"
"testing"
"github.com/buger/jsonparser"
"github.com/tidwall/gjson"
)
@tidwall
tidwall / clone-bytes.go
Created September 15, 2016 16:47
Redcon example using bytes
package main
import (
"log"
"strings"
"sync"
"github.com/tidwall/redcon"
)