Skip to content

Instantly share code, notes, and snippets.

@martinhynar
martinhynar / comp.clj
Last active August 29, 2015 14:10
Correct usage of component
;; This is a function that needs 'resource' started/stopped by the component
(defn index-create [name]
(let [conn (esr/connect (es-url) {:connection-manager __HOW_TO_PASS_COMPONENT_HERE__})]
(esi/create conn name)
))
;; A component that takes care of starting and stopping and stopping http connection manager
@martinhynar
martinhynar / configuration.clj
Last active August 29, 2015 14:13
Example logomotive configuration file
(ns configuration
(:require [logomotive.api.input :as input]
[logomotive.api.output :as output]
[logomotive.api.transform :as transform]
))
; Read events from stdin, keep it as-is
(input/stdin {:format :plain})
; Read events from UDP on port 1984, keep it as-is
(ns core
(:require [cheshire.core :as j]))
(defn -main [& args]
(println "Hello, World!"))
@martinhynar
martinhynar / ast.clj
Created March 21, 2015 17:12
ast evaluation with memoization
(ns ast)
(def ast-eval
(memoize
(fn
([expr]
(if (vector? expr)
(let [head-sym (first expr)]
(cond
(number? head-sym) head-sym
@martinhynar
martinhynar / core.clj
Last active August 29, 2015 14:18
elasticsearch-index-migration
(ns core
(:require
[clojurewerkz.elastisch.rest.document :as doc]
[clojurewerkz.elastisch.rest :as esr]
[clojurewerkz.elastisch.query :as q]
[clojurewerkz.elastisch.rest.response :as esrsp]))
(defn move-documents [conn <-index scroll-id]
(let [;; scroll query - step 2
scan-response (doc/scroll conn scroll-id :scroll "1m")
@martinhynar
martinhynar / 0_reuse_code.js
Last active August 29, 2015 14:20
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
.idea
.vagrant
public DefaultHttpClient createHttpClient() throws Exception {
// Some constants
final int timeout = 10000;
final int HTTP_PORT = 80;
final int HTTPS_PORT = 443;
final String HTTPS = "https";
final String HTTP = "http";
String keystoreName = "keystore";
String keystoreType = "JKS";
String keystorePass = "secret";
@martinhynar
martinhynar / nodes.json
Last active August 29, 2015 14:23
status.json
{
"cluster_name" : "elasticsearch-beta",
"nodes" : {
"y3q_T0UzQ2i_UyVmACqdSg" : {
"name" : "es-data-beta001.dom.example.com",
"transport_address" : "inet[/172.24.249.9:9300]",
"host" : "es-data-beta001",
"ip" : "172.24.249.9",
"version" : "1.5.2",
"build" : "62ff986",
@martinhynar
martinhynar / collectd.conf
Created October 18, 2015 19:09
Quick collect configuration for reading CPU data
Interval 5
Hostname 1.1.1.1
LoadPlugin cpu
LoadPlugin network
<Plugin network>
<Server "localhost" "1984">
</Server>
</Plugin>