Skip to content

Instantly share code, notes, and snippets.

View graph1zzlle's full-sized avatar

Clément HELIOT graph1zzlle

View GitHub Profile
@graph1zzlle
graph1zzlle / BinanceOrderBookFlow.scala
Last active December 19, 2018 12:54
Binance Live Order Book using Akka Stream
/**
* https://github.com/binance-exchange/binance-official-api-docs/blob/master/web-socket-streams.md#how-to-manage-a-local-order-book-correctly
* @param asset
* @param getSnaptshot
*/
class OrderBookFlow(
asset: Asset,
getSnaptshot: Asset => Future[OrderBook]
) extends GraphStage[FlowShape[OrderBookUpdateEvent, OrderBook]] {
(defn compute-percentile
; This function compute a percentile over a sequence of numbers.
[percentile coll]
{:pre [(number? percentile) (> percentile 0) (< percentile 1) (not (empty? coll))]}
(let [sorted (sort coll)
length (count coll)
index (* percentile length)]
(if (== (int index) index)
(let [first (nth sorted (- index 1))
second (nth sorted index)]
@graph1zzlle
graph1zzlle / riemann.config
Last active October 2, 2015 20:27
riemann-scratchpad
;; SCENARIO: Be able to detect high heap pressure on service.
;; -> If during the last x minutes, "heap.usage" values are > 0.70, then alert...
;; Riemann API http://riemann.io/api.html
(defn slack-this-shit [message]
(slack slack-alert-channel {:username "Not so friendly Riemann bot",
:formatter (fn [ev] {:text (str "*"(:service ev)"*" " is in *" (:state ev) "* state on hosts: *" (:host ev) "*. " message),
:icon ":x:"})}))
(def tracking-jvm-pressure-stream

Yesterday I upgraded our running elasticsearch cluster on a site which serves a few million search requests a day, with zero downtime. I've been asked to describe the process, hence this blogpost.

To make it more complicated, the cluster was running elasticsearch version 0.17.8 (released 6 Oct 2011) and I upgraded it to the latest 0.19.10. There have been 21 releases between those two versions, with a lot of functional changes, so I needed to be ready to roll back if necessary.

Our setup:

  • elasticsearch

We run elasticsearch on two biggish boxes: 16 cores plus 32GB of RAM. All indices have 1 replica, so all data is stored on both boxes (about 45GB of data). The primary data for our main indices is also stored in our database. We have a few other indices whose data is stored only in elasticsearch, but are updated once daily only. Finally, we store our sessions in elasticsearch, but active sessions are cached in memcached.

@graph1zzlle
graph1zzlle / test.clj
Created May 7, 2013 05:32
clojure sh*t
;; Fix for the compiling problem on IntelliJ with La-Clojure:
;; Settings -> Compiler -> Clojure Compiler -> Copy Clojure source files to output...
(filter odd? [1 2 3 4 5 6]) ;; => 1 3 5
(first(filter odd? [1 2 3 4 5 6])) ;; => 1
(first '(1 2 3)) ;; => 1
(first [1 2 3]) ;; => 1
;(first (1 2 3)) ;; => error ! because (1 2 3) is not interpreted as a list here
@graph1zzlle
graph1zzlle / someManager.js
Last active December 15, 2015 09:09
example of a NodeJS class
var thing = require('./thing.js');
/*****************************************************
* CLASS DEFINITION
****************************************************/
function someManager() {
this.thing = thing;
this.otherThing = {};
};
@graph1zzlle
graph1zzlle / 0-javascript-notes.md
Last active December 14, 2015 19:29
Notes I have taken throughout my javascript learning, hope it will help someone :0

Notes are actually on:

  • callbacks
  • objects
  • prototype
  • namespaces
@graph1zzlle
graph1zzlle / JSroadmaps.md
Last active November 30, 2017 20:27
Javascript + NodeJS + BackboneJS Learning Roadmap