Skip to content

Instantly share code, notes, and snippets.

View joerx's full-sized avatar
💭
I may be slow to respond.

Jörg Henning joerx

💭
I may be slow to respond.
  • Transferwise
  • Singapore
View GitHub Profile
@joerx
joerx / php-fpm-nginx-errorlog.md
Last active August 6, 2023 16:49
redirect php-fpm output to nginx's error log
  • php process is wrapped like this: PHP file -> php-fpm -> nginx
  • basically means disable all facilities that catch output from the script on it's way to nginx
  • standard error output will the end in Nginx's logging facility

On CentOS

  • make sure your script does not set error_log
  • edit /etc/php-fpm.conf, disable line error_log = /var/log/php-fpm/error.log
  • edit /etc/php-fpm.d/www.conf, disable line starting with php_admin_value[error_log] = ...
  • restart fpm: systemctl restart php-fpm
@joerx
joerx / index.js
Last active May 17, 2023 12:58
Mocking S3 in Node.js using Sinon
var Aws = require('aws-sdk');
var sinon = require('sinon');
// Only works for 'createBucket', 'update' and a few others since most API methods are generated dynamically
// upon instantiation. Very counterintuitive, thanks Amazon!
var createBucket = sinon.stub(Aws.S3.prototype, 'createBucket');
createBucket.yields(null, 'Me create bucket');
// For other methods, we can 'assign' the stubs to the proto, already defined function won't be overridden
var listBuckets = Aws.S3.prototype.listBuckets = sinon.stub();
@joerx
joerx / list-rds-instances.sh
Created June 20, 2018 02:37
List RDS instances, select some fields and render as CSV with aws cli, bash and jq
#!/bin/sh
if [ "$INSTANCE" == "" ]; then
CMD="aws rds describe-db-instances"
else
CMD="aws rds describe-db-instances --db-instance-identifier=$INSTANCE"
fi
echo '"DBInstanceIdentifier","DBInstanceStatus","DBInstanceClass"'
@joerx
joerx / index.js
Created March 20, 2015 00:04
Clear require cache in Node.js
//based on http://stackoverflow.com/questions/9210542/node-js-require-cache-possible-to-invalidate
function clearRequireCache() {
Object.keys(require.cache).forEach(function(key) {
delete require.cache[key];
});
}
var myModule1 = require('./my-module');
console.log(myModule1.counter); // 0
@joerx
joerx / README.md
Last active December 13, 2022 16:24

Minimalistic Development Box with Libvirt

Linux only, requires KVM and QEMU. libvirt and related components need to be installed. Provisions a development VM based on Ubuntu 20.04. Current working directory will be shared with the guest. This is a PoC, not intended to be a fully functional tool. For any serious use case, use something like Vagrant

@joerx
joerx / gist:ea16b9af330e0c346155
Last active January 15, 2021 06:09
Stubbing email sending in tests
// This is the simplest possible approach - use a custom module to wrap a single, pre-configured
// mail transport instance and then use sinon.js to stub out that modules sendmail()
// This approach has its limitations, but it is still better than having 'if(NODE_ENV === 'test')'
// all over the code base.
// -- app/sendmail.js --
var nodemailer = require('nodemailer');
var config = require('config').email;
@joerx
joerx / shorten.sh
Created August 17, 2020 12:01
Shorten AWS region name using regex
echo "eu-central-1" | sed -E s'/([a-z]{2})-([a-z]{1})[a-z]+-([0-9]{1})/|\1\2\3|/' # 'euc1'
{
"[terraform]": {
"editor.formatOnSave": true,
"editor.tabSize": 2
},
"terraform.indexing": {
"enabled": false,
"liveIndexing": false,
"delay": 500,
"exclude": [
@joerx
joerx / gist:6e398bb26e5527a948647a15cb76f7f3
Last active November 30, 2019 09:18
Russian roulette, Terraform edition. Because `rm -rf /` doesn't quite cut it anymore.
RISK=5
[[ $(( ( RANDOM % 6 ) + 1 )) -gt $RISK ]] && echo "terraform destroy -target module.production_db -auto-approve"
# for discussion and alternatives, see https://unix.stackexchange.com/questions/227662/how-to-rename-multiple-files-using-find
find . -type f -name general.tf -not -path '*/.terraform/*' -exec sh -c 'x="{}"; mv "$x" "${x/general/backend}"' \;