Skip to content

Instantly share code, notes, and snippets.

View tuxfight3r's full-sized avatar
:octocat:
Working from home

Mohan Balasundaram tuxfight3r

:octocat:
Working from home
View GitHub Profile
@tuxfight3r
tuxfight3r / pre-commit
Last active August 29, 2015 14:06 — forked from fluxrad/pre-commit
puppet precomit linting
#!/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

tmux cheatsheet

As configured in my dotfiles.

start new:

tmux

start new with session name:

@tuxfight3r
tuxfight3r / gist:080fe5f0db2c57a9e4b3
Last active August 29, 2015 14:10
ping scan a subnet quickly
#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"
@tuxfight3r
tuxfight3r / gist:be4f930a8b055ac932ea
Last active August 29, 2015 14:10
ruby manipulate array with map
#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"
@tuxfight3r
tuxfight3r / gist:39b9f6b1db38cc617ac0
Last active August 29, 2015 14:10
ruby lambda fun
#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)
@tuxfight3r
tuxfight3r / gist:5e60f3ad662bdfb0f8a3
Created November 27, 2014 17:50
ruby block proc and lambda example
# 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 }
@tuxfight3r
tuxfight3r / gist:a350767f32038121d7ee
Created November 27, 2014 17:57
ruby remove nth object by object_id from array
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]
@tuxfight3r
tuxfight3r / gist:7f313cffcebae078d362
Created November 28, 2014 18:00
apache mod_proxy ssl vhost with location based access
#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
@tuxfight3r
tuxfight3r / gist:838dbc4b1464615a016c
Created November 28, 2014 18:08
apache vhost url redirection tricks
#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]
@tuxfight3r
tuxfight3r / gist:2767954b71b8e774e086
Last active August 29, 2015 14:10
sync apache configs/ via git and www folders between nodes
########### 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