Skip to content

Instantly share code, notes, and snippets.

(ns todo-rest.core
(:require [ring.adapter.jetty :as jetty]
[ring.middleware.reload :refer [wrap-reload]]
[compojure.core :refer [defroutes context GET POST PUT DELETE]]
[compojure.route :refer [not-found]])
(:gen-class))
(defroutes app-routes
(GET "/" [] {:status 200 :body "hello world" :headers {}})
(not-found "sorry"))
(def app
(-> app-routes
wrap-json-params
wrap-json-response))
(defroutes app-routes
(GET "/" [] (get-all-todo))
(POST "/" {params :params} (create-todo params))
(context "/:id" [id]
(GET "/" [] (get-todo id))
(PUT "/" {params :params} (update-todo id params))
(DELETE "/" [] (delete-todo id)))
(not-found "sorry"))
(def db-config
{:classname "org.h2.Driver"
:subprotocol "h2"
:subname "mem:todo"
:user ""
:password ""})
(defn pool
[config]
(let [cpds
(defn create-table
[]
(jdbc/db-do-commands
(db-connection)
(jdbc/create-table-ddl :todo_list
[[:id :int "PRIMARY KEY AUTO_INCREMENT"]
[:title "varchar(30)"]
[:text "varchar(1024)"]])))
(defn get-all-todo
[]
(let [result (jdbc/with-db-connection
[conn (db-connection)]
(jdbc/query conn
["select * from todo_list"]))]
{:status 200
:body {:result result}}))
(defn create-todo
package main
import (
"bufio"
"flag"
"fmt"
"log"
"net"
"os"
"strings"
@jacoelho
jacoelho / collectd.go
Last active August 5, 2016 20:48
sample collectd plugin
package main
import (
"flag"
"time"
)
func main() {
var (
interval = flag.Int("interval", 5, "time in seconds between collection")
hostname, _ := os.Hostname()
value := someWork()
fmt.Printf("PUTVAL %s/my-plugin/gauge-my_metric interval=%d N:%s\n", hostname, interval, value)
PUTVAL "$HOSTNAME/exec-magic/gauge-magic_level" interval=$INTERVAL N:$VALUE