Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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 / gist:ed05ecdef9dd5ab60c57
Created July 14, 2014 21:00
/etc/rc.local for Utilite
echo 'net.core.wmem_max=12582912' >> /etc/sysctl.conf
echo 'net.core.rmem_max=12582912' >> /etc/sysctl.conf
echo 'net.ipv4.tcp_rmem= 10240 87380 12582912' >> /etc/sysctl.conf
echo 'net.ipv4.tcp_wmem= 10240 87380 12582912' >> /etc/sysctl.conf
echo 'net.ipv4.tcp_window_scaling = 1' >> /etc/sysctl.conf
echo 'net.ipv4.tcp_timestamps = 1' >> /etc/sysctl.conf
echo 'net.ipv4.tcp_sack = 1' >> /etc/sysctl.conf
echo 'net.ipv4.tcp_no_metrics_save = 1' >> /etc/sysctl.conf
echo 'net.core.netdev_max_backlog = 5000' >> /etc/sysctl.conf
echo performance > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
-----BEGIN PGP PUBLIC KEY BLOCK-----
Version: GnuPG/MacGPG2 v2.0.18 (Darwin)
mQINBFHK/6cBEAC+XPwiHQ3eZ1B9OfnyITX5ADFlks06JP0icrcmMDDNEpTYSC+q
FHJ/D/uEdKM03RalVGZ8KES/TG3kjaEPUODR8adRWP8EYm/EGTozn6qO5YwiB/7q
8v9R9R+ZZwivRvM56054A/RgAgy09Qf50uLgRGryRyDuPEwyVDJEcGglCwOR+oep
FGnxi7kmO2RTVmHHEAQWoCZDbkgyQctmh++99UKdKMG7yhlX8EMOmN+iYAW4ZXS/
fFSOKTdgb26gNUhaBuKboHmCEx3JwZXnkHZ853jXFWQndb70+wcVnP9i04vM2Nsn
8ACBVg0y7zheGV6eBz9X+MD/+fSui7syINYDW9oiswQm5A9tgP/Bl+XDqI5HZIOZ
twuO7YJBQfWX5Js6Qc1qxaSl96VzlNoL1xXx+ULBqgyaEOTd0M4AcJW3V0vnaTd2
@niklasvincent
niklasvincent / build-nginx.sh
Last active October 11, 2019 04:44
Build script for statically compiled nginx 1.4.7 with OpenSSL 1.0.1e.
#!/bin/bash
set -e
NGINX_VERSION="1.6.0"
NGINX_TARBALL="nginx-${NGINX_VERSION}.tar.gz"
PCRE_VERSION="8.34"
PCRE_TARBALL="pcre-${PCRE_VERSION}.tar.gz"
OPENSSL_VERSION="1.0.1g"
OPENSSL_TARBALL="openssl-${OPENSSL_VERSION}.tar.gz"
#!/bin/bash
# Set Graphite host
GRAPHITE="172.16.20.1"
GRAPHITE_PORT="2003"
stats() {
HOSTNAME="mediacenter"
DATE=$(date +%s)
echo "server.${HOSTNAME}.${1} ${2} ${DATE}" | nc $GRAPHITE $GRAPHITE_PORT -w 1
@niklasvincent
niklasvincent / post-commit
Created February 19, 2013 16:00
Add the following to ./git/hooks/post-commit and change your UID and TOKEN (obtained from the user -> settings dialog). More information here https://github.com/lefnire/habitrpg/wiki/API
# Gain XP on HabitRPG
HABITRPG_UID="xxxxx"
HABITRPG_TOKEN="yyyyyy"
curl -X POST -H 'Content-Type:application/json' \
"https://habitrpg.com/v1/users/${HABITRPG_UID}/tasks/git/up" \
-d "{\"apiToken\":\"${HABITRPG_TOKEN}\", \"title\":\"Git commit\", \"service\":\"git\", \"icon\":\"https://github.com/favicon.ico\"}" 1>/dev/null 2
>&1
@niklasvincent
niklasvincent / gist:2894406
Created June 8, 2012 08:09
Geo comparison
// MySQL
$sql = "SELECT all, the fields, you, want, ((ACOS(SIN(c.Latitude * PI() / 180) * SIN(" . $lat . " * PI() / 180) + COS(c.Latitude * PI() / 180) * COS(" . $lat . " * PI() / 180) * COS((c.Longitude - " . $lng . ") * PI() / 180)) * 180 / PI()) * 60 * 2) as distance FROM places ORDER BY distance DESC;";
// MongoDB
$this->places->find(array( 'loc' => array( '$near' => array($lat, $lng) ) ));