Skip to content

Instantly share code, notes, and snippets.

Keybase proof

I hereby claim:

  • I am kian on github.
  • I am kian (https://keybase.io/kian) on keybase.
  • I have a public key ASD6LfcUUNFAkK_n0Yu1vBWJOI7GrPvfHhBn4m2tzhewcAo

To claim this, I am signing this object:

resource "aws_cloudwatch_metric_alarm" "www-production-high-alb-5xx" {
alarm_name = "www-production-high-alb-5xx"
comparison_operator = "GreaterThanThreshold"
evaluation_periods = "1"
metric_name = "HTTPCode_ELB_5XX_Count"
namespace = "AWS/ApplicationELB"
period = "60"
statistic = "Sum"
threshold = "30"
alarm_actions = ["arn:aws:sns:us-east-1:1234567:slack-alerts"]

Profiling with Xdebug/Webgrind

One of the important steps in improving application performance is profiling. Xdebug produces information for each request. Webgrind is a web interface which ingests this data for analysis.

Setup

The Xdebug extension is already installed for you. On production, it can be enabled as needed.

  1. Open public_html/.htaccess
  2. Set xdebug.profiler_enable to 1 and save. Alternatively, edit the next line instead to profile select requests.
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "PapertrailLogArchive",
"Effect": "Allow",
"Principal": {
"AWS": ["arn:aws:iam::719734659904:root"]
},
"Action": [
kian@zergtrap ~/src/puppet-placelocal $ yarn --help
Usage: yarn install [flags]
Options:
-h, --help output usage information
-V, --version output the version number
--offline
--prefer-offline
kian@zergtrap ~/src/puppet-placelocal $ yarn add user-home
yarn add v0.15.1
info No lockfile found.
[1/4] Resolving packages...
[2/4] Fetching packages...
[3/4] Linking dependencies...
[4/4] Building fresh packages...
success Saved lockfile.
success Saved 2 new dependencies.
├─ os-homedir@1.0.2
dependencies:
override:
- sudo -H pip install awsebcli --upgrade --ignore-installed
test:
override:
- echo 'we run the tests after deploy'
deployment:
stage:
<script>
// BEAT MESSAGE
try {
window.wixBiSession = {
initialTimestamp : Date.now(),
viewerSessionId: 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c)
{ var r = Math.random()*16|0, v = c == 'x' ? r : (r&0x3|0x8); return v.toString(16); }
)
};
(new Image()).src = 'http://frog.wix.com/bt?src=29&evid=3&pn=1&et=1&v=3.0&vsi=' + wixBiSession.viewerSessionId +
@kian
kian / foo.php
Last active January 21, 2016 20:26
--omg-optimized
<?php
private function predictQualityForFilesize($width, $height, $bytes)
{
/*
* There's apparently some overhead in the JPEG file format that
* scales with the square root of the file's size. Accounting for it
* causes the bpp-to-quality curves for the different dimensions to
* line up better.
*
###
### start nginx container with syslog driver
###
[ec2-user@ip-172-31-48-33 ~]$ sudo docker run -d --name testing2 -P --log-driver=syslog nginx
eef985214f466aaa84c4d969c8843c00ff13e38ecbf4377519c1a15290e6a4d0
[ec2-user@ip-172-31-48-33 ~]$ sudo docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
eef985214f46 nginx "nginx -g 'daemon of 7 seconds ago Up 6 seconds 0.0.0.0:32770->80/tcp, 0.0.0.0:32769->443/tcp testing2