Skip to content

Instantly share code, notes, and snippets.

@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 / 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
(ns core
(:require [cheshire.core :as j]))
(defn -main [& args]
(println "Hello, World!"))
@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
@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 / ES_Update.md
Last active August 29, 2015 14:08
Update existing document in ES?

Have existing document already in ES

{
  "service" : "A",
  "timestamp" : "2014-06-06T12:12:59.456+00:00"
}

and want to update it to get this

@martinhynar
martinhynar / gist:d149019d11e76f05da12
Last active February 22, 2023 12:55
ElasticSearch: Updating nested document in array

Given the document

curl -XPUT 'localhost:9200/test/me/here' -d '{
  "top" : [
    { "searchkey" : "change"},
    { "searchkey" : "keep"}
  ]
}'
import multiprocessing
import time
import os
class PMonitor(multiprocessing.Process):
def __init__(self, process_id):
super(PMonitor, self).__init__()
self.process_id = str(process_id)
self.semaphore = multiprocessing.Event()
@martinhynar
martinhynar / jps.py
Last active August 29, 2015 14:04
Java's jps in Python using Twitter Commons
import os
import glob
import twitter.common.java.perfdata as twc
if __name__ == '__main__':
pattern = os.path.join('/tmp', 'hsperfdata_*', '*')
for path in glob.glob(pattern):
root, pid = os.path.split(path)
dirname = os.path.basename(root)
# PATHS
WORKBENCH=~/Workbench
PATH=~/bin:${PATH}
JAVA_HOME=/usr/java/latest/
PATH=${JAVA_HOME}:${PATH}
TMP=/tmp; export TMP
TMPDIR=$TMP; export TMPDIR