Skip to content

Instantly share code, notes, and snippets.

View toff63's full-sized avatar

Christophe Marchal toff63

View GitHub Profile
@toff63
toff63 / terraform_retrieve_secret_aws.tf
Created December 10, 2018 17:21
How to retrieve a secret stored in AWS Secret Manager in terraform.
variable "region" {}
variable "access_key" {}
variable "secret_key" {}
provider "aws" {
version = "~> 1.25"
region = "${var.region}"
access_key = "${var.access_key}"
secret_key = "${var.secret_key}"}

Most of the sqls come from https://tapoueh.org/blog/2018/05/postgresql-data-types-point/

Setup

docker pull kartoza/postgis:9.6-2.4
wget http://download.geonames.org/export/dump/allCountries.zip
unzip allCountries.zip
wget http://download.geonames.org/export/dump/admin2Codes.txt
wget http://download.geonames.org/export/dump/shapes_simplified_low.json.zip
@toff63
toff63 / currying_elixir.ex
Created July 18, 2018 17:28
Currying is not very straight forward in Elixir, but it is still doable
defmodule Math do
def sum(a,b), do: a+b
def add1(a) do
f = fn(a) -> sum(1,a) end
f.(a)
end
def three() do
f = fn() -> add1(2) end
TMP_DIR=$(mktemp -d /tmp/lambda-XXXXXX)

Run Es in docker:

docker pull docker.elastic.co/elasticsearch/elasticsearch:5.1.2
docker run -p 9200:9200 -e "http.host=0.0.0.0" -e "transport.host=127.0.0.1" docker.elastic.co/elasticsearch/elasticsearch:5.1.2
curl -u `docker-machine ip \`docker-machine active\``:9200

Password is changeme Source

curl -X PUT localhost:9200/customer/external/1?pretty -d '{"name": "John Doe"}'

Create alias in 2.2:

curl -XPOST 'http://localhost:9200/_aliases' -d '{"actions" : [{ "add" : { "index" : "customer", "alias" : "people" } }]}'

Create alias in 5.1:

Zen discovery process

There is absolutely no documentation about this part beside the code. Here is the result of what is in the ES 5.1 code.

The node starts when the method start is called in class Node. Several services are started, including the cluster and discovery service.

Cluster state

It represents the state of the cluster. It is immutable, except the routing nodes structure which is built on demand based on the routing table and cluster status. It can only be updated by the master node and is controlled by a single thread in the ClusterService. After every update, the method publish for the Discovery class sends the new version of the cluster state to all other nodes. The publishing process depends on the type of discovery chosen: Zen, AWS, GCP, Azure, etc.

@toff63
toff63 / clean-git-history-before-PR.md
Last active October 24, 2016 14:06
Gives a way to push a clean commit history before sending a Pull Request

Get the difference between your branch and the one you are going to do the PR:

git log --oneline my_branch...master
# Should return something like
# 5bf92dc Merge remote-tracking branch 'origin/master' into my_branch
# 51a2689 Move some code in try/catch to avoid crashing daemon
# 481b548 Fix my_process status
# 6c0747b Fix linux service failing to stop properly and then start

Write those lines down in your favorite text editor for future use.

# build/gate/gate-web/config/gate.yml
server:
port: 8084
services:
deck:
baseUrl: http://localhost:9000
orca:
baseUrl: http://localhost:8083
front50:

Install git-pylint-commit-hook

$ pip install git-pylint-commit-hook

Add git pylint to a git repo as a hook

$ cd my_git_repo/.git/hooks
$ echo '#!/bin/sh
git-pylint-commit-hook
' > pre-commit