Skip to content

Instantly share code, notes, and snippets.

@hamstar
hamstar / binstat
Last active December 11, 2015 17:48
print out the mem and cpu used by a process (or multiple processes with the same name) for munin
#!/bin/bash
function get_cpu_usage() {
cpu=`ps auwx|grep "$1"|grep -v 'grep'|tr -s ' ' ' ' | cut -d' ' -f3|awk '{s+=$1}END{print s}' `;
}
function get_mem_usage() {
mem=`ps auwx|grep "$1"|grep -v 'grep'|tr -s ' ' ' ' | cut -d' ' -f4|awk '{s+=$1}END{print s}' `;
}
u = User.first
p = Page.first
# Only like this does it work
p.user = u
u.pages << p
# this does not work (does not set the user_id in the pages table)
> p.user(u).save
(0.1ms) begin transaction
@hamstar
hamstar / howto.md
Created November 7, 2012 04:20
Merging braincase documentation from github into braincase

Copying user docs from Github into Braincase

Install Ruby and the tool

apt-get install ruby
wget https://raw.github.com/gist/3606882/ecefcd097bb8ae8bf163c30e643ecdc8f57abd53/md2cre.rb

Pull down the wiki repo

@hamstar
hamstar / gist:3722236
Created September 14, 2012 14:28
init file for running rails apps as a service (in screen) - redmine is example
#!/usr/bin/ruby
app_name="redmine"
pid_file="/var/run/#{app_name}.pid"
user="redmine"
appdir="/home/#{user}/redmine"
LOAD_RVM="source /home/#{user}/.rvm/scripts/rvm"
START_APP="RAILS_ENV=production passenger start -a 127.0.0.1 -p 3002"
STOP_APP="RAILS_ENV=production passenger stop -a 127.0.0.1 -p 3002"
@hamstar
hamstar / build.sh
Created September 9, 2012 07:18
autodeb builder for Braincase
#!/bin/bash
# Some vars
REPO="https://github.com/hamstar/Braincase.git";
LREPO="/var/www/test/repo";
BRANCH="sprint2"; # this could be replaced with ref
BUILDDIR="$LREPO/packages/debian";
WEBDIR="/var/www/test";
# Refresh the repo
@hamstar
hamstar / pngur
Created September 6, 2012 23:35
download a png image from imgur
#!/bin/bash
hash=$1;
wget "http://i.imgur.com/$hash.png"
cd /root/build
rm -fr packages/debian/var packages/debian/usr packages/debian/etc
cp -Rf usr etc var -t packages/debian
chmod a+x packages/debian/usr/bin/*
dpkg-deb --build packages/debian
@hamstar
hamstar / dump_descs.sh
Created August 26, 2012 07:24
Dumps the descriptions of all the tables in a MySQL database
#!/bin/bash
echo -n "Enter the mysql database name: "
read DB;
echo -n "Enter the mysql user name: "
read USER;
echo -n "Please enter the mysql password: ";
set -v off;
#!/usr/bin/ruby
$threshold = 60
$external_snapshots = "/media/external/snapshots"
$system_snapshots = "/backup/backintime/AKSCOU01.local/root/1"
# ensure correct drive is mounted
# enforce the threshold
freespace = `df -l|grep /media/external|tr -s ' ' ' '|cut -d' ' -f4`.chomp.to_i
@hamstar
hamstar / comment-ref-issue-labels-userscript.js
Created August 16, 2012 11:04
Userscript to show labels next to issue references in the comments of git issues
// ==UserScript==
// @name Git Reference Labels
// @namespace http://gist.github.com/3369304
// @version 0.2.1
// @description Shows labels next to issue references in the comments of git issues
// @include https://github.com/*/*/issues/*
// @copyright 2012+, Robert McLeod
// @require https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js
// ==/UserScript==