Skip to content

Instantly share code, notes, and snippets.

@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"
@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 / 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 / nodejs.yml
Created May 9, 2014 12:50
Example Ansible playbook for installing node.js from source
- hosts: all
vars:
node_version: "0.10.28"
tasks:
- name: Check for node.js
shell: test "$(node -v 2> /dev/null)" = v{{node_version}}
register: nodejs_installed
ignore_errors: True
tags:
- nodejs
@leihog
leihog / gist:3749523
Created September 19, 2012 13:01
Fix Shatter(Steam version) on OS X - Indie Humble bundle 6
Start Terminal.app and then type:
$ cd ~/Library/Application Support/Steam/SteamApps/common/Shatter/Shatter.app/Contents/Frameworks/Cg.framework
$ ln -s Versions/1.0/Cg Cg
@leihog
leihog / colorize.php
Created June 28, 2012 13:38
colorize function in PHP
<?php
function colorize($str, $fg = 'white', $bg = false)
{
$fg = str_replace(array('-','_'), '', $fg);
switch($fg) {
case 'black': $fg = "0;30"; break;
case 'yellow': $fg = "1;33"; break;
case 'brown': $fg = "0;33"; break;
case 'green': $fg = "0;32"; break;
@leihog
leihog / main.php
Created May 14, 2012 07:22
loadModules() for modular habari plugins
<?php
class MyPlugin extends Plugin
{
private $modules = array();
private function loadModules()
{
$base_path = dirname(__FILE__) . '/modules/';
$dh = opendir( $base_path );
@leihog
leihog / todo.vim
Created February 17, 2012 13:29
Barebones example of how to make a simple vim syntax file.
" Barebones example of how to make a simple vim syntax file.
" Language: todofile
" Maintainer: leihog
"if exists ("b:current_syntax")
" finish
"endif
let b:current_syntax = "todo"
" v:folddashes a string that contains dashes to represent the foldlevel.
diff --git 0.11/access/macro.py 0.11/access/macro.py
index 7ea2e23..70ed06f 100644
--- 0.11/access/macro.py
+++ 0.11/access/macro.py
@@ -11,6 +11,7 @@ import re
from trac.core import *
from trac.wiki.api import IWikiMacroProvider
from trac.wiki.formatter import format_to_html
+from trac.perm import PermissionSystem, IPermissionStore
@leihog
leihog / vhosts.sh
Created July 25, 2011 07:28
Lighttpd include all vhosts in path in to lighttpd.conf
#!/bin/bash
#
# Use this to include all vhost files in to lighttpd.conf
# In lighttpd.conf add the line: include_shell "/etc/lighttpd/vhosts.sh"
#
VHOST_PATH="/etc/lighttpd/vhosts/*"
for f in $VHOST_PATH
do
cat $f