Skip to content

Instantly share code, notes, and snippets.

@jordanorelli
Created March 17, 2012 22:00
Show Gist options
  • Save jordanorelli/2065698 to your computer and use it in GitHub Desktop.
Save jordanorelli/2065698 to your computer and use it in GitHub Desktop.
pissing contest
package main
import (
"fmt"
"github.com/ziutek/mymysql/mysql"
"io"
"net/http"
// "runtime"
_ "github.com/ziutek/mymysql/thrsafe"
)
var db mysql.Conn
func indexHandler(w http.ResponseWriter, r *http.Request) {
// fmt.Println(runtime.NumCPU(), "\t", runtime.NumGoroutine())
rows, _, err := db.Query("select * from user")
if err != nil {
fmt.Println("Error sending query\n")
http.Error(w, err.Error(), http.StatusInternalServerError)
}
for _, row := range rows {
io.WriteString(w, row.Str(1) + "\n")
}
// io.WriteString(w, "hello, world!")
}
func main() {
db = mysql.New("unix", "", "/tmp/mysql.sock", "pissing", "pissing", "pissing")
err := db.Connect()
if err != nil {
fmt.Println("Error connecting to database.\n")
panic(err)
}
fmt.Println("Go serving on port 8080")
http.HandleFunc("/", indexHandler)
http.ListenAndServe(":8080", nil)
}
import tornado.ioloop
import tornado.web
from tornado.database import Connection
db = Connection("localhost", "pissing", user="pissing", password="pissing")
class IndexHandler(tornado.web.RequestHandler):
def get(self):
for row in db.query("select * from user"):
self.write(row.username + "\n")
application = tornado.web.Application([
(r'/', IndexHandler),
])
if __name__ == "__main__":
application.listen(8888)
tornado.ioloop.IOLoop.instance().start()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment