Skip to content

Instantly share code, notes, and snippets.

@BigRedS
BigRedS / mdstat
Created January 23, 2013 13:42
/proc/mdstat
Personalities : [raid1]
md2 : active raid1 sda3[0] sdb3[1]
474712640 blocks [2/2] [UU]
[=======>.............] resync = 35.5% (168726976/474712640) finish=161.0min speed=31669K/sec
md1 : active (auto-read-only) raid1 sda2[0] sdb2[1]
3903680 blocks [2/2] [UU]
md0 : active raid1 sda1[0] sdb1[1]
9767424 blocks [2/2] [UU]
@BigRedS
BigRedS / gist:4087324
Created November 16, 2012 13:22
"See full trace by running task with --trace"
root@host:/opt/redmine-2.1.2# rake generate_secret_token 2> ~/rake.err
root@host:/opt/redmine-2.1.2# wc ~/rake.err
104 273 11505 /root/rake.err
root@host:/opt/redmine-2.1.2# tail ~/rake.err
/usr/local/rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:245:in `load'
/usr/local/rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.8/lib/rails/engine.rb:425:in `block in load_tasks'
/usr/local/rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.8/lib/rails/engine.rb:425:in `each'
/usr/local/rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.8/lib/rails/engine.rb:425:in `load_tasks'
/usr/local/rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.8/lib/rails/application.rb:145:in `load_tasks'
/usr/local/rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.8/lib/rails/railtie/configurable.rb:30:in `method_missing'
@BigRedS
BigRedS / gist:3823729
Created October 2, 2012 22:29
Downloading zipped attachment with Courriel
sub saveAttachments{
my $message = shift;
my $f_zip = shift;
my $email = Courriel->parse(text => $message, is_character => 1);
my @parts = $email->parts();
for( my $part = 0; $part < $email->part_count(); $part++){
my $mime_type = $parts[0]->container->{'_parts'}[$part]->content_type->mime_type;
if ($mime_type =~ /x-zip-compressed/){
my %zipped = %{$parts[0]->container->{'_parts'}[$part]};
my $zip64ref = $zipped{'encoded_content_ref'};
@BigRedS
BigRedS / gist:3714038
Created September 13, 2012 12:35
iotop
root@amazing:/home/avi# iotop -b -o | grep jbd
256 be/3 root 0.00 B/s 27.08 K/s 0.00 % 9.39 % [jbd2/sda1-8]
256 be/3 root 0.00 B/s 34.98 K/s 0.00 % 27.22 % [jbd2/sda1-8]
256 be/3 root 0.00 B/s 177.07 K/s 0.00 % 12.71 % [jbd2/sda1-8]
256 be/3 root 0.00 B/s 27.05 K/s 0.00 % 6.10 % [jbd2/sda1-8]
256 be/3 root 0.00 B/s 15.55 K/s 0.00 % 54.32 % [jbd2/sda1-8]
256 be/3 root 0.00 B/s 110.91 K/s 0.00 % 34.90 % [jbd2/sda1-8]
256 be/3 root 0.00 B/s 123.75 K/s 0.00 % 0.14 % [jbd2/sda1-8]
256 be/3 root 0.00 B/s 120.23 K/s 0.00 % 12.42 % [jbd2/sda1-8]
^C
@BigRedS
BigRedS / gist:3637043
Created September 5, 2012 14:01
OpenSSL
avi@marvellous:~$ openssl s_client -ssl2 -connect somehost:25
unknown option -ssl2
usage: s_client args
-host host - use -connect instead
-port port - use -connect instead
-connect host:port - who to connect to (default is localhost:4433)
-verify arg - turn on peer certificate verification
-cert arg - certificate file to use, PEM format assumed
-certform arg - certificate format (PEM or DER) PEM default
@BigRedS
BigRedS / gist:3286376
Created August 7, 2012 15:27
Pro string handling in PHP
$perl = 'if($_ =~ /(\d+)\s*Ram,?\s*(\d+)\s*Cores,?\s*(\d+)%\s*CPU,?\s*(\d+)\s*GB\s*disk/i){ print "$1 $2 $3 $4";}';
$string = `echo $description | perl -ne '$perl'`;
list ($ram, $cores, $cpu, $disk) = explode(" ", $string);
$specs[$ram] = array(
'ram' => $ram,
'cores' => $cores,
'cpu' => $cpu,
'disk' => $disk,
);
@BigRedS
BigRedS / gist:3090340
Created July 11, 2012 13:17
How to send an email
echo "To: to@domain.com
from: you@somewhere-else.com
Subject: testing
this is just a test" | sendmail -t
@BigRedS
BigRedS / gist:3048404
Created July 4, 2012 17:13
Run on an 'old' host, generates a script to run on the new host to replicate the users with UIDs and passwords.
echo '#! /bin/bash'; egrep '(/bin/bash|/bin/sh)$' /etc/passwd | while read i; do uid=$(echo $i|awk -F: '{print $3}'); uname=$(echo $i|awk -F: '{print $1}') ; if [ ! -z $uid ]; then if [ $uid -gt 999 ]; then passwd=$(cat /etc/shadow | awk -F: '{print $1 " " $2}' | egrep "^${uname} " | awk '{print $2}') ; args="-M "; if [ ! -z "$passwd" ]; then if [ "$passwd" != "*" ]; then args="$args -p \047$passwd\047"; fi; fi; echo $i | awk -F: -v args="$args" '{print "useradd " args " -u " $3 " " $1 }'; fi; fi ; done
@BigRedS
BigRedS / lego.user.js
Created July 3, 2012 21:03
Greasemonkey script for the correction of erroneous pluralisation of 'Lego'
// ==UserScript==
// @name lego
// @namespace http://avi.co
// @description Remove erroneous pluralisation of 'Lego'
// @include *
// @version 1
// ==/UserScript==
strings = document.evaluate("//text()", document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
var match = /\blegos\b/gi;
@BigRedS
BigRedS / lego.user.js
Created July 3, 2012 21:01
Greasemonkey script for removing erroneous pluralisation of 'Lego'
// ==UserScript==
// @name lego
// @namespace http://avi.co
// @description Remove erroneous pluralisation of 'Lego'
// @include *
// @version 1
// ==/UserScript==
strings = document.evaluate("//text()", document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
var match = /\blegos\b/gi;