As configured in my dotfiles.
start new:
tmux
start new with session name:
#!/bin/bash | |
# pre-commit git hook to check the validity of a puppet manifest | |
# | |
# Prerequisites: | |
# gem install puppet-lint puppet | |
# | |
# Install: | |
# /path/to/repo/.git/hooks/pre-comit | |
# Source RVM if needed |
As configured in my dotfiles.
start new:
tmux
start new with session name:
#Ping scan a subnet | |
seq 254 | xargs -P255 -I% sh -c "ping -q -c1 -w1 192.168.0.% > /dev/null || echo 192.168.0.% DOWN" |
#ruby manipulate array values with map | |
irb(main):040:0> array=%w(one two three four five) | |
=> ["one", "two", "three", "four", "five"] | |
irb(main):042:0> array.map{|item| "ldap://#{item}" }.join(',') | |
=> "ldap://one,ldap://two,ldap://three,ldap://four,ldap://five" |
#Basic lambda Hello World | |
irb(main):122:0> test=lambda{"Hello World"} | |
=> #<Proc:0x00000001393e28@(irb):122 (lambda)> | |
irb(main):123:0> test.call | |
=> "Hello World" | |
#lambda function to remove nth object from an array | |
irb(main):115:0> str=lambda {|arr,div| arr.each_with_index.map{|x,i| i+=1; next if i % div == 0; x}.compact } | |
=> #<Proc:0x00000001570a70@(irb):115 (lambda)> | |
irb(main):116:0> str.call((0..20).to_a, 3) |
# Block Examples | |
[1,2,3].each { |x| puts x*2 } # block is in between the curly braces | |
[1,2,3].each do |x| | |
puts x*2 # block is everything between the do and end | |
end | |
# Proc Examples | |
p = Proc.new { |x| puts x*2 } |
str=lambda {|arr,div| arr.each_with_index.map{|x,i| i=i+1; next if i % div == 0; x}.compact } | |
=> #<Proc:0x000000015a7138@(irb):138 (lambda)> | |
irb(main):139:0> str.call((0..20).to_a, 3) | |
=> [0, 1, 3, 4, 6, 7, 9, 10, 12, 13, 15, 16, 18, 19] | |
irb(main):140:0> str.call((1..20).to_a, 3) | |
=> [1, 2, 4, 5, 7, 8, 10, 11, 13, 14, 16, 17, 19, 20] |
#Sample apache mod_proxy ssl vhost with location based access | |
<VirtualHost *:443 *:60443> | |
ServerName www.nerdplanet.co.uk | |
ServerAlias nerdplanet.co.uk | |
DocumentRoot /var/www/vhosts/nerdplanet.co.uk/ | |
#LogLevel debug | |
CustomLog /var/log/httpd/nerdplanet.co.uk_access_log combined | |
ErrorLog /var/log/httpd/nerdplanet.co.uk_error_log | |
SSLEngine on |
#Redirect NonSSL to SSL | |
RewriteEngine on | |
RewriteCond %{HTTPS} off | |
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L] | |
#Redirect if the host name not begins with WWW | |
RewriteEngine on | |
RewriteCond %{HTTP_HOST} !^www.nerdplanet.co.uk$ [NC] | |
RewriteRule ^(.*)$ https://www.nerdplanet.co.uk$1 [R=301] | |
########### apache-sync.sh | |
#!/bin/bash | |
#Purpose:To update apache configs via git to the rest of the apache servers | |
#Note: This script should only be run from node01 to keep things consistent | |
#Date: 11/09/2014 | |
#Author: Mohan | |
#HOST IPS are read from hosts file in the current dir | |
. hosts |