Skip to content

Instantly share code, notes, and snippets.

View estahn's full-sized avatar
👨‍💻
ʕʘ̅͜ʘ̅ʔ – ʕ•̫͡•ʕ*̫͡*ʕ•͓͡•ʔ-̫͡-ʕ•̫͡•ʔ

Enrico Stahn estahn

👨‍💻
ʕʘ̅͜ʘ̅ʔ – ʕ•̫͡•ʕ*̫͡*ʕ•͓͡•ʔ-̫͡-ʕ•̫͡•ʔ
View GitHub Profile
@estahn
estahn / postgresql_add_primary_key.sql
Created October 4, 2013 13:10
PostgreSQL - Add primary key to an existing Table
ALTER TABLE "public"."foo" ADD COLUMN "id" INTEGER;
CREATE SEQUENCE "public"."foo_id_seq";
UPDATE foo SET id = nextval('"public"."foo_id_seq"');
ALTER TABLE "public"."foo" ALTER COLUMN "id" SET DEFAULT nextval('"public"."foo_id_seq"');
ALTER TABLE "public"."foo" ALTER COLUMN "id" SET NOT NULL;
ALTER TABLE "public"."foo" ADD UNIQUE ("id");
ALTER TABLE "public"."foo" DROP CONSTRAINT "foo_id_key" RESTRICT;
ALTER TABLE "public"."foo" ADD PRIMARY KEY ("id");
aws ec2 describe-instances \
--filters Name=dns-name,Values=ec2-12-345-678-90.myregion.compute.amazonaws.com \
| jq '.Reservations [] .Instances [] .InstanceId'
aws ec2 describe-instances \
--filters Name=dns-name,Values=ec2-12-345-678-90.myregion.compute.amazonaws.com \
| jq '.Reservations [] .Instances [] .InstanceId' \
| xargs -n1 aws ec2 get-console-output --instance-id \
| jq '.Output'
/**
* WebP support check
*
* The cookie will be set for the top level domain, e.g. ".zanui.com.au".
* This will enable access from "static.zanui.com.au".
*
* Script might not work for local environments.
*
* @author <a href="mailto:enrico.stahn@rocket-internet.de">Enrico Stahn</a>
*/
@estahn
estahn / designer.html
Created July 26, 2014 02:07
designer
<link rel="import" href="../core-icon-button/core-icon-button.html">
<link rel="import" href="../core-toolbar/core-toolbar.html">
<polymer-element name="my-element">
<template>
<style>
:host {
position: absolute;
width: 100%;
@estahn
estahn / open_files_per_process.sh
Last active August 29, 2015 14:21
Number of open files per process
#!/bin/sh
processes=$(lsof | cut -f1 -d" " | sort | uniq | xargs -n1 -I% sh -c 'echo % `pidof % | sed -e "s/ /,/g"`' | cut -d" " -f1 -s)
for process in $processes; do
echo $process $(pidof $process | sed -e "s/ /,/g" | xargs -I% -n1 sh -c 'lsof -a -p % | wc -l')
done

Nginx Tuning For Best Performance

For this configuration you can use web server you like, i decided, because i work mostly with it to use nginx.

Generally, properly configured nginx can handle up to 400,000 to 500,000 requests per second (clustered), most what i saw is 50,000 to 80,000 (non-clustered) requests per second and 30% CPU load, course, this was 2xIntel Xeon with HT enabled, but it can work without problem on slower machines.

You must understand that this config is used in testing environment and not in production so you will need to find a way to implement most of those features best possible for your servers.

First, you will need to install nginx, my way to install nginx is compiling it from source, but for now we will use apt-get

@estahn
estahn / check-ssl-all-elbs.sh
Last active June 22, 2016 03:43
Check SSL on all ELBs
#!/bin/sh
ELBS=`aws elb describe-load-balancers | jq -r '.LoadBalancerDescriptions[] | select(.ListenerDescriptions[].Listener.SSLCertificateId) | .DNSName'`
for elb in ${ELBS}; do
OUTPUT=`echo | timeout 2 openssl s_client -connect ${elb}:443 2>/dev/null | openssl x509 -noout -enddate 2> /dev/null`
echo "${elb};${OUTPUT}"
done
@estahn
estahn / update_docker.sh
Last active March 23, 2017 00:12 — forked from dylanscott/update_docker.sh
Travis Update to Docker 17.03.0
#!/usr/bin/env bash
set -euo pipefail
echo "Installing docker engine"
sudo sh -c 'echo "deb https://apt.dockerproject.org/repo ubuntu-$(lsb_release -cs) main" > /etc/apt/sources.list.d/docker.list'
curl -fsSL https://apt.dockerproject.org/gpg | sudo apt-key add -
sudo apt-key fingerprint 58118E89F3A912897C070ADBF76221572C52609D
sudo apt-get update
sudo apt-get -y install "docker-engine=17.03.0~ce-0~ubuntu-$(lsb_release -cs)"
allow_duplicates: yes
dependencies:
- { role: roleA, tasks: [1] }