Skip to content

Instantly share code, notes, and snippets.

View xymor's full-sized avatar

Raphael Miranda xymor

View GitHub Profile
@xymor
xymor / build.gradle
Created January 24, 2019 19:39
kotlin gradle idea
import java.text.SimpleDateFormat
buildscript {
ext.kotlin_version = '1.3.11'
ext.spek_version = '1.0.9'
ext.junit_runner_version = '1.0.0-M3'
repositories {
mavenCentral()
maven { url "https://plugins.gradle.org/m2/" }
@xymor
xymor / monitoring-mongo.sh
Created January 21, 2019 18:02
Monitor your OpLog using AWS Cloudwatch
#!/bin/bash
JSON=`mongo --quiet -u root -p pass --authenticationDatabase admin --eval "JSON.stringify(db.getReplicationInfo())" database.com.br:27017/local`
TIMEDIFF=`echo $JSON | jq '.timeDiffHours'`
echo $TIMEDIFF
aws cloudwatch put-metric-data --region sa-east-1 --metric-name MongoTimeDiffHours --namespace Midas --value "`echo $TIMEDIFF`" --timestamp `date -u "+%Y-%m-%dT%H:%M:%SZ"`
@xymor
xymor / hazelcast-aws.groovy
Created December 18, 2018 19:35
connect to aws hazelcast cluster
@Grab('com.hazelcast:hazelcast:3.7.4')
@Grab('com.hazelcast:hazelcast-aws:2.1.0')
import com.hazelcast.config.*
import com.hazelcast.core.Hazelcast
import com.hazelcast.spi.discovery.impl.*
import com.hazelcast.aws.*
import com.hazelcast.core.ILock
@xymor
xymor / RemoveDuplicates.java
Created April 23, 2018 14:43
hackerrank RemoveDuplicates from linkedlist
/*
Node is defined as
class Node {
int data;
Node next;
}
*/
Node RemoveDuplicates(Node head) {
Node current = head;
@xymor
xymor / query.kt
Created April 19, 2018 21:16
How to run a mongo aggregation pipeline using plain json mongo query insteal of spring data dsl
fun reportServices(stores: List<Store>, start: LocalDate, end: LocalDate, pageable: Pageable): Pair<List<java.util.HashMap<*, *>>, Int> {
val pipeline = """
[
{#match: {
'processed.accountingCodePrimary': {#ne: null},
'processed.specialization': {#ne: 'NONE'},
'processed.authorizer.#id': {#eq: 'WK'},
'processed.transactionCodeConsult': {#ne: 'YES'}
}},
@xymor
xymor / TheTimeinWords.kt
Created April 19, 2018 14:55
The Time in Words from Hackerrank in kotlin
val dictionary = mapOf<Int,String>(
1 to "one",
2 to "two",
3 to "three",
4 to "four",
5 to "five",
6 to "six",
7 to "seven",
8 to "eight",
9 to "nine",
@xymor
xymor / install.sh
Created March 31, 2018 18:48
Installing a fresh ubuntu development workstation
#Installs sdkman
curl -s "https://get.sdkman.io" | bash
#Installs python
curl -L https://github.com/pyenv/pyenv-installer/raw/master/bin/pyenv-installer | bash
#Installs ruby
gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
curl -sSL https://get.rvm.io | bash -s stable --ruby
@xymor
xymor / docker-replicaset.sh
Created October 18, 2017 16:10
docker-replicaset.sh
sudo mkdir -p /var/mongodb/mongodb-1 /var/mongodb/mongodb-2 /var/mongodb/mongodb-3
sudo docker run -d -it -p 27018:27017 -v /var/mongodb/mongodb-1:/data/db -v /var/config:/var/config --name mongodb-1 -d mongo mongod --replSet midas --bind_ip 0.0.0.0
sudo docker run -d -it -p 27019:27017 -v /var/mongodb/mongodb-2:/data/db -v /var/config:/var/config --name mongodb-2 -d mongo mongod --replSet midas --bind_ip 0.0.0.0
sudo docker run -d -it -p 27020:27017 -v /var/mongodb/mongodb-3:/data/db -v /var/config:/var/config --name mongodb-3 -d mongo mongod --replSet midas --bind_ip 0.0.0.0
mongo 127.0.0.1:27018 <<<"rs.initiate({_id: 'midas', members: [ {_id: 0, host:'10.224.28.131:27018'}, {_id: 1, host:'10.224.28.131:27019'}, {_id: 2, host:'10.224.28.131:27020'}]})"
# curl -s https://gist.githubusercontent.com/xymor/4cf2bd593d89f4722d0a4d69654ac762/raw/6feaef84c7906be7b4a48f1ce9691442a378471c/docker-ubuntu.sh | bash
# curl -sL https://git.io/vyQoI | sudo bash
apt-get remove docker docker-engine
apt-get install \
linux-image-extra-$(uname -r) \
linux-image-extra-virtual -y
apt-get install \
#!/bin/bash
# Expects Ubuntu 16.06 (xenial) and kernel 4.x.
# Based upon a blog post by Zach at http://zachzimm.com/blog/?p=191
set -eux
# Have the user call sudo early so the credentials is valid later on
sudo whoami
sudo apt-get install libssl-dev -y