Skip to content

Instantly share code, notes, and snippets.

@niklasvincent
niklasvincent / TestSSL.java
Created June 25, 2015 11:09
Test SSL connection in JVM
import java.io.FileOutputStream;
import java.io.ObjectOutputStream;
import java.security.cert.CertPath;
import java.security.cert.CertificateFactory;
import java.util.ArrayList;
import java.util.List;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLSession;
import javax.net.ssl.SSLSocket;
@niklasvincent
niklasvincent / testHook.js
Created July 24, 2015 09:38
My first hook.io microservice
module['exports'] = function echo (hook) {
// Access Node.js HTTP Request and Response objects
var req = hook.req,
res = hook.res;
// Use NPM Modules
var faker = require('faker');
res.write('<strong>hello</strong> ');
res.write(req.headers["x-forwarded-for"] + '<br/>');
res.end(faker.hacker.phrase());
};
@niklasvincent
niklasvincent / projects.html
Created July 30, 2015 13:27
Public Github repositories sorted by number of watchers
{% if site.github.public_repositories %}
{% assign sorted_repositories = site.github.public_repositories | sort: 'watchers_count' %}
{% for repository in sorted_repositories reversed %}
<h2><a href="{{ repository.html_url }}" target="_blank">{{ repository.name }}</a></h2>
<p>{{ repository.description }}</p>
{% endfor %}
{% endif %}
@niklasvincent
niklasvincent / validate-cloudformation.sh
Last active October 3, 2018 12:43
Validate CloudFormation during build
#!/bin/bash
# Add this script to your cloudformation directory (we have ours in the project root).
# Then set up a build step in Team City that executes the custom script:
#
# [[ -f ./cloudformation/validate-cloudformation.sh ]] && ./cloudformation/validate-cloudformation.sh
#
# That way branches without the script will still build.
#
# Make sure your CI user has the following policy attached to it for AWS:
@niklasvincent
niklasvincent / nginx-build.sh
Last active March 18, 2016 12:25
nginx-build.sh
#!/bin/bash
set -e
NGINX_VERSION="1.9.12"
NGINX_TARBALL="nginx-${NGINX_VERSION}.tar.gz"
PCRE_VERSION="8.38"
PCRE_TARBALL="pcre-${PCRE_VERSION}.tar.gz"
OPENSSL_VERSION="1.0.1s"
OPENSSL_TARBALL="openssl-${OPENSSL_VERSION}.tar.gz"
@niklasvincent
niklasvincent / elb-connection-draining-status.sh
Created April 25, 2016 13:14
elb-connection-draining-status.sh
#!/bin/bash
PROFILE="${1}"
ELBS=$(aws --profile ${PROFILE} elb describe-load-balancers --page-size 100 | jq -r '.LoadBalancerDescriptions[].LoadBalancerName')
for ELB in ${ELBS}; do
CONNECTION_DRAINING=$(aws --profile ${PROFILE} elb describe-load-balancer-attributes --load-balancer-name ${ELB} | jq ".LoadBalancerAttributes.ConnectionDraining.Enabled")
printf "%-32s %s\n" $ELB $CONNECTION_DRAINING
done
@niklasvincent
niklasvincent / config.py
Created June 16, 2016 20:57
Download and parse configuration file from AWS S3
import boto3
import ConfigParser
import tempfile
class ConfigFromS3(object):
def __init__(self, bucket_name, key, region_name):
"""Read configuration file from S3 and parse it"""
defaults = {
@niklasvincent
niklasvincent / lets-encrypt-sha256.sh
Last active September 9, 2023 09:04
Let's Encrypt Certificates SHA256 fingerprint
#!/bin/bash
BASE_URL="https://letsencrypt.org/certs/"
CERTIFICATES="lets-encrypt-x3-cross-signed.pem lets-encrypt-x4-cross-signed.pem lets-encrypt-x1-cross-signed.pem lets-encrypt-x2-cross-signed.pem"
for CERTIFICATE in $CERTIFICATES; do
echo "# $CERTIFICATE "
curl --silent "${BASE_URL}${CERTIFICATE}" | openssl x509 -noout -fingerprint -sha256 -inform pem | cut -d'=' -f2 | tr '[:upper:]' '[:lower:]' | sed -e 's/://g' |
done
@niklasvincent
niklasvincent / README.md
Last active July 10, 2020 14:18
ACM Migration Summary

ACM Migration Summary

This script iterates all ELBs in an account and lists whether they use Amazon Certificate Manager for SSL or not.

If your SSL certificate name ends with -expYYYY-MM-DD, the expiry date will also be listed and the final list is sorted by days until expiry.

## Install dependencies

Make sure you have virtualenv installed

@niklasvincent
niklasvincent / 07-djikstra.py
Created September 2, 2016 20:28
Grokking Algorithms
#!/usr/bin/env python
graph = {
"start": {
"a" : 6,
"b" : 2
},
"a" : {
"fin" : 1
},
"b" : {