Skip to content

Instantly share code, notes, and snippets.

@jacoelho
jacoelho / day_4.py
Created December 4, 2017 20:24
naive approach
from collections import defaultdict
def valid(L):
d = defaultdict(int)
for v in L:
if d[v]:
return False
else:
d[v] += 1
@jacoelho
jacoelho / day_3.py
Created December 4, 2017 20:03
advent of code 2017 day 3
import math
def coordinates(n):
d = math.floor(0.5 * (math.sqrt(n - 1) + 1))
nsig = n - (4 * d ** 2 + 1)
if nsig <= -2* d:
return(d, 3*d+nsig)
elif -2*d <= nsig <= 0:
@jacoelho
jacoelho / alb-asg.tf
Created December 4, 2017 10:54
alb asg
resource "aws_alb_target_group" "test" {
name = "test-alb"
port = 443
protocol = "HTTPS"
vpc_id = "${aws_vpc.test.id}"
deregistration_delay = 200
stickiness {
type = "lb_cookie"
cookie_duration = 10000
}
@jacoelho
jacoelho / day_1.py
Last active December 2, 2017 12:14
advent 2017 day
def transform(input):
return [int(x) for x in input]
def consecutive(L):
for prev, n in zip(L, L[1:] + L[:1]):
if prev == n:
yield n
for v in [ "1122", "1111", "1234", "91212129"]:
print(sum(transform(consecutive(v))))
@jacoelho
jacoelho / haproxy.cfg
Last active October 3, 2017 22:25
haproxy redis
defaults REDIS
mode tcp
timeout connect 3s
timeout server 6s
timeout client 6s
frontend ft_redis
bind *:6379 ssl crt /etc/haproxy/certificate.pem ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-DSS-AES128-GCM-SHA256:kEDH+AESGCM:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-DSS-AES128-SHA256:DHE-RSA-AES256-SHA256:DHE-DSS-AES256-SHA:DHE-RSA-AES256-SHA:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!3DES:!MD5:!PSK
default_backend bk_redis
@jacoelho
jacoelho / docker-compose.yml
Created October 2, 2017 14:40
alert manager mesh setup
version: "3"
services:
alertmanager:
image: prom/alertmanager
ports: ["9093:9093"]
command: [ "-config.file=/etc/alertmanager/config.yml", "-storage.path=/alertmanager" ]
networks:
- backend
@jacoelho
jacoelho / pprof-auth.go
Created September 29, 2017 09:10
pprof auto
package main
import (
"fmt"
"net/http"
"net/http/pprof"
"strings"
)
func handler(w http.ResponseWriter, r *http.Request) {
@jacoelho
jacoelho / AWS-CSA-A-Notes.md
Last active August 29, 2017 08:23 — forked from agussman/AWS-CSA-A-Notes.md
Notes from studying for the AWS Certified Solutions Architect Exam. I felt well-prepared for the exam and passed with a 94%. Please reach out with any corrections or questions.

External Resources

type Cache struct {
kv map[string]*bufio.Reader
http.RoundTripper
}
func (c *Cache) RoundTrip(req *http.Request) (*http.Response, error) {
if req.Method != "GET" {
return c.RoundTrip(req)
}
// http.Client - comments removed
type Client struct {
Transport RoundTripper
CheckRedirect func(req *Request, via []*Request) error
Jar CookieJar
Timeout time.Duration
}