Skip to content

Instantly share code, notes, and snippets.

@leihog
leihog / OAuthToken.php
Created November 15, 2015 12:07
Example of how to use reflection to extract values from and restore a MangoPaySDK OAuthToken
use \MangoPay\Libraries\OAuthToken;
function extractValues(OAuthToken $token) {
$ref = new \ReflectionClass(OAuthToken::CLASS);
$values = [];
$props = $ref->getProperties();
foreach($props as $prop) {
if (!$prop->isPublic()) {
@leihog
leihog / chkdiskspace
Last active June 1, 2016 08:39
Check disk space
#!/bin/bash
MAX=80
EMAIL=email@example.com
HOST=`hostname`
DISKS=`df -h | awk -v max=$MAX 'NR>1 && NF>1 { perc = (NF==5) ? $4 : $5; sub("%","",perc); if (0+perc >= 0+max) print perc"%", $NF }'`
if [ "$DISKS" != "" ]; then
echo -e "Warning we are running out of disk space on $HOST \n$DISKS" | mail -s "Running out of disk space on $HOST" $EMAIL
fi
@leihog
leihog / gist:8ea31cde841e7049ea7d49ab3e88835b
Created August 30, 2016 12:35
run-local-script-remote
#!/bin/sh
cmd=${0##*/}
ssh -t $1 "$(sed '1,/^#xxxREMOTExxx#$/d' < $0) > /tmp/$cmd.$$.sh && sh /tmp/$cmd.$$.sh; rm /tmp/$cmd.$$.sh"
exit $?
#xxxREMOTExxx#
#!/bin/sh
echo "This is executed on the remote server"