Skip to content

Instantly share code, notes, and snippets.

@drewr
drewr / fix-facter-path.hs
Last active January 6, 2016 18:30
Normalize some paths until we fix the AMIs
{-# LANGUAGE OverloadedStrings #-}
module Main where
-- Make static:
-- ghc -O2 --make -static -optc-static -optl-static -fvia-C -optl-pthread fix-facter-path.hs
import Turtle
import Data.Text (Text, pack)
import Filesystem.Path.CurrentOS (fromText, basename, dirname)
import Prelude hiding (FilePath)
@drewr
drewr / jenkins.log
Created November 9, 2015 23:03
Touching the filesystem from Java in a Jenkins run is tricky
Started by user anonymous
Building remotely on hotel (server) in workspace /h/jenkins/workspace/elastic,runbld,master
No JDK named ‘null’ found
[elastic,runbld,master] $ /usr/local/bin/runbld /tmp/hudson5777054172083384843.sh
user.dir /h/jenkins/workspace/elastic,runbld,master
>>>>>>>>>>>> SCRIPT EXECUTION BEGIN >>>>>>>>>>>>
"repo dir" "/h/jenkins/git-cache/elastic/runbld"
Exception in thread "main" java.lang.ExceptionInInitializerError
at java.nio.file.FileSystems.getDefault(FileSystems.java:176)
at java.io.File.toPath(File.java:2234)
(ns jenky.main
(:gen-class)
(:import (hudson.remoting FileSystemJarCache
Launcher
Channel$Mode
StandardOutputStream)))
(defn -main [& args]
(println "jenky start" (with-out-str (pr args)))
(let [in System/in
#!/usr/bin/env stack
-- stack runghc --package turtle
{-# LANGUAGE OverloadedStrings #-}
import Data.List
import Turtle
main :: IO ()
main = do
@drewr
drewr / query.sh
Last active August 29, 2015 14:23
Cardinality agg across downloads
curl -s localhost:9200/download-2015.06/_search\?search_type=count -d '
{
"aggs": {
"ip_count": {
"cardinality": {
"field": "last_origin.raw"
}
}
},
"query": {
+---------------+ +---------------+ +---------------+
| | | | | |
| | | | | |
| APP | | APP | | APP |
| | | | | |
| +----+ +----+ | | +----+ +----+ | | +----+ +----+ |
| | LS | | ES | | | | LS | | ES | | | | LS | | ES | |
+-+----+-+----+-+ +-+----+-+----+-+ +-+----+-+----+-+
| | |
| | |
@drewr
drewr / request.hs
Last active August 29, 2015 14:20
Extract single key/value from jsonl stdin
#!/usr/bin/env runhaskell
{-# LANGUAGE OverloadedStrings #-}
import Prelude hiding (unlines, lines, length, intercalate, interact)
import Data.Aeson
import Data.Text.Lazy (Text, unlines, lines, length, intercalate, pack)
import Data.Text.Lazy.IO (interact)
import Data.Text.Lazy.Encoding (encodeUtf8)
import Control.Applicative
@drewr
drewr / save-indices.sh
Last active August 29, 2015 14:20
Snap your marvel indices, without snapshot/restore
#!/bin/sh
pat='.marvel-*'
idxs=`curl -s localhost:9200/_cat/indices/${pat}\?h=index | sort`
single=`echo $idxs | tail -1`
id=`echo $pat | sed 's/[^a-zA-Z]*//g'`-`date -u +%s`
d=/tmp/$id
if [ -d $d ]; then
echo $d exists, delete and rerun $0
% curl -s -vv https://download.elasticsearch.org/health.txt
* Trying 54.225.133.195...
* Connected to download.elasticsearch.org (54.225.133.195) port 443 (#0)
* successfully set certificate verify locations:
* CAfile: /opt/local/share/curl/curl-ca-bundle.crt
CApath: none
* TLSv1.2, TLS Unknown, Unknown (22):
* TLSv1.2, TLS handshake, Client hello (1):
* SSLv2, Unknown (22):
* TLSv1.2, TLS handshake, Server hello (2):
@drewr
drewr / 01readme.md
Last active August 29, 2015 14:13
ES manual _optimize for great memory savings (pre-Lucene 4.10.3)

Usage

curl -s https://gist.githubusercontent.com/drewr/b920250c3211650bdd40/raw/optimize.py | python - INDEXNAME

Sample output

% curl -O download.elasticsearch.org/stream2es/stream2es; chmod +x stream2es