Skip to content

Instantly share code, notes, and snippets.

View posilva's full-sized avatar
💭
I may be slow to respond.

Pedro Marques da Silva posilva

💭
I may be slow to respond.
View GitHub Profile
@posilva
posilva / top_metrics.py
Created June 8, 2020 15:50
Get Datadog Top Metrics
import time
import urllib.parse
import urllib.request
import json
import os
import csv, sys
from urllib.error import HTTPError
def http_get(path):
@posilva
posilva / ListenSocketState.sh
Created January 14, 2020 15:35
Some cmd snippets
netstat -an|awk '/tcp/ {print $6}'|sort|uniq -c
@posilva
posilva / httpc.py
Created January 6, 2020 12:09
Python3 http request
from urllib import request, parse
# some json data
data = parse.urlencode({'secret':'a', 'response':'b'}).encode()
req = request.Request("https://www.google.com/", data=data) # this will make the method "POST"
resp = request.urlopen(req)
print(resp.read())
@posilva
posilva / dbg.erl
Created December 26, 2019 16:11
DBG Erlang DNS Resolution
%% Check the default lookup resolution option
inet_db:res_option(lookup).
%% Set the lookup resolution option giving priority to the ERVM dns client
inet_db:set_lookup([dns, native]).
%% Setup DBG (DO NOT USE IT IN PRODUCTION) good to run in the local erl console
dbg:stop_clear(). % Stop in any case
dbg:start(). % start application
dbg:tracer(). % create tracer
dbg:p(all, c). % allow for all process
@posilva
posilva / install.sh
Created November 13, 2019 11:45
Try Dax
#!/bin/bash
pip install amazon-dax-client
@posilva
posilva / ami-fetch
Last active February 13, 2020 09:15
AMI Fetch
AMI_FILTER=amzn-ami-hvm-2018.03*-x86_64-ebs
for REGION in us-east-1 us-west-2 us-west-1 eu-west-1 eu-central-1 ap-northeast-1 ap-southeast-1 ap-southeast-2 us-east-2
do
aws --region $REGION ec2 describe-images --owners amazon \
--filters "Name=name,Values=$AMI_FILTER" \
--query 'sort_by(Images, &CreationDate)[] ' | jq -c 'max_by(.CreationDate) | {region: "'$REGION'", name: .Name, image: .ImageId, date: .CreationDate} '
done
@posilva
posilva / DynamoDbGrammar.g4
Created September 4, 2019 09:48
DAX antlr grammar and tokens
/*
* Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"). You may not
* use this file except in compliance with the License. A copy of the License
* is located at
*
* http://aws.amazon.com/apache2.0/
*
* or in the "license" file accompanying this file. This file is distributed on
@posilva
posilva / inet_utils.erl
Created August 14, 2019 21:24 — forked from marcelog/inet_utils.erl
inet_aton, inet_ntoa, ip_between functions for erlang. Convert an ip address address to/from its uint32 and text representations, check if the give ip address falls in a specific network range
-module(inet_utils).
-export([inet_aton/1, inet_ntoa/1]).
-export([ip_between/3]).
%% @doc Converts a binary string with a human readable ip
%% address representation into an uint32.
-spec inet_aton(binary()) -> pos_integer().
inet_aton(Ip) ->
[O1Bin, O2Bin, O3Bin, O4Bin] = binary:split(Ip, <<".">>, [global]),
@posilva
posilva / ddb.py
Created July 23, 2019 14:17
python ddb tests
#
# Copyright 2010-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
#
# This file is licensed under the Apache License, Version 2.0 (the "License").
# You may not use this file except in compliance with the License. A copy of
# the License is located at
#
# http://aws.amazon.com/apache2.0/
#
@posilva
posilva / dbpool.go
Created March 2, 2019 00:50
Example of the usage of go-poolboy to wrap connections to a database and have a dedicated pool of workers to connect
package main
import (
"database/sql"
"fmt"
_ "github.com/go-sql-driver/mysql"
poolboy "github.com/posilva/go-poolboy"
"strconv"
)