Skip to content

Instantly share code, notes, and snippets.

@jeffsteinmetz
jeffsteinmetz / gist:063bd3237033f3af2ed9
Last active October 20, 2023 22:20
Generate Unique, Hashed, Random Token in Scala for use in API calls or as an OAuth Token Bearer
import scala.util._
import java.security.SecureRandom
import java.security.MessageDigest
/*
* Generates a Bearer Token with a length of
* 32 characters (MD5) or 64 characters (SHA-256) according to the
* specification RFC6750 (http://tools.ietf.org/html/rfc6750)
*
* Uniqueness obtained by hashing system time combined with a
@jeffsteinmetz
jeffsteinmetz / gist:2ea8329c667386c80fae
Last active August 29, 2015 14:13
Determine list [array] size in elasticsearch issue
# tested against elasticsearch 1.4.1
# groovy script does not accuratly count number of elements in list
# if you don't add a mapping to "not_analyze" it is even worse
INDEX_NAME='list-count-test'
NODE='localhost'
curl -XDELETE 'http://'$NODE':9200/'$INDEX_NAME
curl -XPUT 'http://'$NODE':9200/'$INDEX_NAME'/' -d '{
@jeffsteinmetz
jeffsteinmetz / equilibrium.scala
Created September 3, 2015 06:15
My purely functional Scala solution to the equilibrium index problem by codility
// My scala solution (purely functional with no mutable variables)
// to the sample codility problem for finding
// any equilibrium index in an array of ints with up to
// 10 million entries. Description of problem is here:
// http://blog.codility.com/2011/03/solutions-for-task-equi.html
// this is O(N) and uses a scala List (instead of an Array) to maximize the
// speed of .head and .tail operations
import scala.annotation.tailrec
@jeffsteinmetz
jeffsteinmetz / elasticsearch-rolling-upgrade.yml
Created December 18, 2015 19:08
Ansible Elasticsearch Rolling Upgrade Example
# Ansible
# Rolling Upgrade of Elasticsearch
# author: Jeff Steinmetz, @jeffsteinmetz
# tested with Ansible 1.8.2
---
- name: Elasticsearch rolling upgrade
# Modify hosts to match your inventory group strategy.
hosts: search
serial: 1