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 / install_golang.sh
Last active December 18, 2017 10:24 — forked from jniltinho/install_golang.sh
Install Golang on Linux
#!/bin/bash
## Install Golang 1.9 64Bits on Linux (Debian|Ubuntu|OpenSUSE|CentOS)
## http://www.linuxpro.com.br/2015/06/golang-aula-1-instalacao-da-linguagem-no-linux.html
## Run as root (sudo su)
## Thank's @geosoft1 | @gwmoura
GO_URL="https://storage.googleapis.com/golang"
GO_VERSION=${1:-"1.9.2"}
GO_FILE="go$GO_VERSION.linux-amd64.tar.gz"
@posilva
posilva / ldapc.erl
Created March 5, 2018 09:32
Simple LDAP Authentication in Erlang (escript)
-module(ldapc).
%% API exports
-export([main/1]).
-include_lib("eldap/include/eldap.hrl").
%%====================================================================
%% API functions
%%====================================================================
@posilva
posilva / context.ex
Created March 31, 2018 23:07 — forked from ericstumper/context.ex
Guardian Authentication with Absinthe GraphQL in Elixir
defmodule Languafy.Web.Context do
@behaviour Plug
import Plug.Conn
alias Languafy.User
def init(opts), do: opts
def call(conn, _) do
case build_context(conn) do
{:ok, context} ->
@posilva
posilva / build.sh
Last active September 27, 2018 13:18
Helper script to test cloudformation scripts
#!/usr/bin/env bash
# Helper commands for clouformation deploy in the EC2 instances
# curl http://169.254.169.254/latest/user-data
# cat /var/log/cloud-init-output.log
# sudo yum install htop tmux tcpdump telnet -y
# describe stack
# this parameters are not passed by command line parameters
# to ensure that the developer does not hit a different STACK NAME or template by mistake
@posilva
posilva / Ldap-Escript
Created October 16, 2018 13:20
Erlang Ldap client to auth against AD
-module(ldapc).
%% API exports
-export([main/1]).
-include_lib("eldap/include/eldap.hrl").
%%====================================================================
%% API functions
%%====================================================================
@posilva
posilva / disable.sh
Last active November 21, 2023 18:15
Remove/Disable Ubuntu SystemD Daily.Timers
# References:
#
# https://cinhtau.net/2016/12/09/disable-apt-auto-update-and-upgrade/
# https://unix.stackexchange.com/questions/315502/how-to-disable-apt-daily-service-on-ubuntu-cloud-vm-image
# https://askubuntu.com/questions/824718/ubuntu-16-04-unattended-upgrades-runs-at-random-times/831206
apt-get -y purge update-notifier-common ubuntu-release-upgrader-core landscape-common unattended-upgrades
systemctl kill --kill-who=all apt-daily.service
systemctl kill --kill-who=all apt-daily-upgrade.service
@posilva
posilva / email.erl
Created January 11, 2019 14:12 — forked from seriyps/email.erl
Send emails using Erlang gen_smtp shortcut.
% Send plaintext email using gen_smtp https://github.com/Vagabond/gen_smtp
% This function sends email directly to receiver's SMTP server and don't use MTA relays.
%
% Example plaintext email:
% Mail = mail_plain(<<"Bob <sender@example.com>">>, <<"Alice <receiver@example.com>">>, <<"The mail subject">>, <<"The mail body">>),
% send_email(Mail).
%
% Example email with image attachment:
% ImgName = "image.jpg",
% {ok, ImgBin} = file:read_file(ImgName),
@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"
)
@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 / 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]),