Thursday, March 21, 2019

.bash_aliases set permissions for web directories

# Copy the following and paste into bottom of: /home/username/.bash_aliases

web-dir() {
  if [ $UID -ne 0 ]; then
    if [ -d "$1" ]; then
        sudo find "$1" -type f -exec chmod 664 {} \;
        sudo find "$1" -type d -exec chmod 775 {} \;
    else
        echo "DIR not found"   
    fi
  else    
    if [ -d "$1" ]; then
        find "$1" -type f -exec chmod 664 {} \;
        find "$1" -type d -exec chmod 775 {} \;
    else
        echo "DIR not found"   
    fi
  fi       
}

# The above Linux script will set folder permissions so group www has read/write....

#.bashrc should have: umask 0002

# usermod -g www-data MYUSERNAME

Wednesday, March 20, 2019

Dynamic Form Data

<html>
<head>
    <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
</head>
<body>
<form method="POST" action="test.php">   
     <div id="dynamicInputsA">
        <span id="clone1">Pets<input type="text" name="myInputs[]"></span>
     </div>
     <input type="button" value="Add another text input" onClick="addInput('dynamicInputsA', 'clone1');">
     <input type="submit" value="test"/>
</form>    
<script>
    var counter = [];
    var limit = 3;
    function removeInput(divName, olddiv) {
        document.getElementById(divName).removeChild(olddiv);
        counter[divName]--;
    }
    function addInput(divName, clone){
         if (counter[divName] === undefined) {
             counter[divName] = 1;
         }
         if (counter[divName] == limit)  {
              alert("You have reached the limit of adding " + limit + " inputs");
         } else {
              var newdiv = document.createElement('div');
              var content = document.getElementById(clone).innerHTML;
              newdiv.innerHTML = content + "<button type='button' onClick='removeInput(\""+divName+"\", this.parentElement);'>Remove</button>";
              document.getElementById(divName).appendChild(newdiv);
              counter[divName]++;
         }
    }
</script>

</body>
</html>


Here is test.php:

    $myInputs = $_POST["myInputs"];

    foreach ($myInputs as $eachInput) {
         echo $eachInput . "<br>";
    }

Friday, January 5, 2018

Save Project Ideas

Enter your Idea for our Project:
<form method="post">
  <textarea rows="4" cols="50" name="Idea" maxlength="255" placeholder="Enter your Idea Here!!"></textarea><br/>
  <input type="text" name="Name" value="" placeholder="Enter your Name Here!!"/>
  <input type="submit" />
</form>
<?php
$dbname = 'Ideas.sqlite';
$exists = true;
if (! file_exists($dbname) ) {
  touch($dbname);
  chmod($dbname, 0660);
  $exists = false;
}

function no_results() {
  echo "No Ideas - Posted yet!!";
  exit;
}

try {
  $db = new PDO("sqlite:{$dbname}");
 
  if ($exists === false) {
    $db->exec("CREATE TABLE Ideas (Id INTEGER PRIMARY KEY, Idea TEXT, Name TEXT, Done INTEGER)");
  }

  if (isset($_POST['Idea']) && !empty($_POST['Idea'])) {
    $name = (isset($_POST['Name']) && !empty($_POST['Name'])) ? ucwords($_POST['Name']) : 'Guest';

    $insert = $db->prepare("INSERT INTO Ideas (Idea, Name, Done) VALUES (:Idea, :Name, 0);");
    $insert->bindParam(':Idea', $_POST['Idea'], PDO::PARAM_STR);
    $insert->bindParam(':Name', $name, PDO::PARAM_STR);
    $insert->execute();
  }

  if (isset($_GET['DoneID']) && intval($_GET['DoneID']) > 0) {
    $id = intval($_GET['DoneID']);
    $complete = $db->prepare("UPDATE Ideas SET Done=1 WHERE Id=:Id LIMIT 1;");
    $complete->bindParam(':Id', $id, PDO::PARAM_INT);
    $complete->execute();
  }

  $result = $db->query('SELECT Id, Idea, Name FROM Ideas WHERE Done=0');
 
  if ($result === false) {
    no_results();
  }
 
  $rows = $result->fetchAll(PDO::FETCH_ASSOC);

  if (count($rows) === 0) {
    no_results();
  }

  echo "<table border=1>";
  $mark = (isset($_GET['unlock'])) ? '<td>Mark as Complete</td>' : '';
  echo "<tr><td>Idea#</td><td>Idea</td><td>by Name</td>{$mark}</tr>";

  foreach ($rows as $row) {
    echo "<tr><td>" . $row['Id'] . "</td>";
    echo "<td>" . htmlentities($row['Idea'], ENT_QUOTES) . "</td>";
    echo "<td>" . htmlentities($row['Name'], ENT_QUOTES) . "</td>";
    if (isset($_GET['unlock'])) {
      echo "<td><a href=\"?DoneID=" . $row['Id'] . "\">Done</a></td></tr>";
    }
  }
  echo "</table>";
  $db = NULL;
} catch (PDOException $e) {
  echo 'Exception : ' . $e->getMessage();
}

Thursday, September 28, 2017

Small Dependency Injection

File: main.php

require 'configure.php';
require 'di.php';
require 'config.php';
require 'db_service.php';
require 'data_model.php';

$db = configure::get('di')->get_service('db');

$data_model = new data_model($db);
$data_model->show_data();

File: configure.php

final class configure {
 /**
  * @var array $config All configured settings handled by this class
  */
 private static $config = array(); 
  
 /**
  * Protected constructor to prevent instance creation
  */
 protected function __construct() { }
 
 /**
  * Fetches a setting set from using Configure::set() or add or update
  *
  * @param string $name The name of the setting to get
  * @param string $key [optional] The Array Key to fetch
  * @return mixed The setting specified by $name, or null if $name was not set
  * 
  * return type: ?array
  */
 public static function get(string $name, $key = false) {
   if (isset(self::$config[strtolower($name)])) {
      $a = self::$config[strtolower($name)];
      if ($key === false) {
         return $a;
      } 
      if (isset($a[$key])) {
         return $a[$key];
      }
   }
   return null;
 }
  
 /**
  * Checks if the setting exists
  *
  * @param string $name The name of the setting to check existance
  * @return boolean true if $name was set, false otherwise
  */
 public static function exists(string $name): bool {
    if (array_key_exists(strtolower($name), self::$config)) {
       return true;
    }
    return false;
 }

  /**
   * Overwrite/Update/Add to $config
   * @param string $name the main key to update
   * @param string $key the sub key
   * @param type $value the data to update
   */
  public static function update(string $name, string $key, $value): void {
 self::$config[strtolower($name)][strtolower($key)] = $value;
  }
  
  /**
   * Add to existing data without loss... to $config
   * @param string $name the main key
   * @param string $key the sub key
   * @param type $value new data to add
   */
  public static function add(string $name, string $key, $value): void {
 self::$config[strtolower($name)][strtolower($key)][] = $value;
  }
    
 /**
  * Frees the setting given by $name, if it exists. All settings no longer in
  * use should be freed using this method whenever possible
  *
  * @param string $name The name of the setting to free
  */
 public static function free(string $name): void {
    if (self::exists($name)) unset(self::$config[strtolower($name)]);
 }
 
 /**
  * Adds the given $value to the configuration using the $name given
  *
  * @param string $name The name to give this setting. Use Configure::exists()
  * to check for pre-existing settings with the same name
  * @param mixed $value The value to set
  */
 public static function set(string $name, $value): void {
    self::$config[strtolower($name)] = $value;
 }
 
}

file: di.php

final class di {
 protected $services = [];
 
 public function register(string $service_name, callable $callable): void {
  $this->services[$service_name] = $callable;
 }
 
 public function get_service(string $service_name, array $args = [] ) {
  if (! array_key_exists($service_name, $this->services)) {
   throw new \Exception("The Service: {$service_name} does not exists.");
  }
  return $this->services[$service_name]($args);
 }
 
 public function __set(string $service_name, callable $callable): void {
  $this->register($service_name, $callable);
 }
 
 public function __get(string $service_name) {
  return $this->get_service($service_name);
 }
 
 public function list_services_as_array(): array { 
  return array_keys($this->services); 
 }
 
 public function list_services_as_string(): string { 
  return implode(',', array_keys($this->services)); 
 }
 
}

configure::set('di', new di());

file: config.php

configure::set('database', array(
  'TYPE' => 'mysql',
  'HOST' => 'localhost',
  'PORT' => '3306',
  'NAME' => 'MyCoolDB',
  'USER' => 'root',
  'PASS' => 'BatMan55', 
));

file: db_service.php

configure::get('di')->register('db', function() {
 $db_info = configure::get('database');
 $db_socket = (isset($db_info['SOCKET'])) ? $db_info['SOCKET'] : false;
 $db_conn = (! empty($db_socket)) ? ":unix_socket={$db_socket};" : "host={$db_info['HOST']};";
 $dsn = "{$db_info['TYPE']}:{$db_conn}port={$db_info['PORT']};dbname={$db_info['NAME']}";
 return new \pdo($dsn, $db_info['USER'], $db_info['PASS']);
});

file: data_model.php

class data_model {

 private $db;
 
 public function __construct(PDO $db) {
  $this->db = $db;
 }
 
 public function show_data(): void {
  $q = $this->db->query("SELECT `data` FROM `test`");

  foreach($q as $row) {
   echo $row['data'] . "<br>";
  }
 }
 
}

If, you do not want to do a bunch of require statements to load all the code up front...

Try Aura.Di
Please leave a comment below, how do you use DI with a framework?

Wednesday, September 20, 2017

How to use my "Auto Git" for Linux

The scripts used here are all valid for Linux...
Sorry, Windows users. I just don't use Windows...
I'm not sure if any of this will apply for Mac users...?
First, create your code and setup git...then create the Repository/git init.... seek online help if you've never done this. GitHub - Start a new git repository

Create the files: gpull, gpull-and-push, and do_git from the posts I made...here. Add them to the folder: /usr/local/bin

nano /usr/local/bin/gpull
nano /usr/local/bin/gpull-and-push
nano /usr/local/bin/do_git
Note: that I did not give the files any file extension. Do not add the .sh unless you update the source file do_git to reflect those changes! Do:
chmod +x /usr/local/bin/gpull
chmod +x /usr/local/bin/gpull-and-push
chmod +x /usr/local/bin/do_git

Now, from Ubuntu Mate. Click System. Click Preferences. Click Look and Feel.
Then, click Main Menu.

Create a New Menu. Name it Git. With the menu Git Selected...Create New Items for each of your git Projects...

Click New Item. Launcher Properties: Type: Application in Terminal.
Name: Your Git Project Folder Name.
Command: /usr/local/bin/do_git "/var/www/PROJECTFOLDERwithGIT"
Click Close.

If, you do not want to install Mate, create an Desktop/Menu folder using your system... See: how-to-create-a-desktop-shortcut for Ubuntu
Add a new Feature to your code base....

Try it out...Click Applications. Click Git. Click Git Project Folder Name.

Follow the on-screen instructions....:
Your git project path will be displayed first.
Along with all branches created.
Type 0 and Press the Enter Key.
Type 2 and Press Enter.

A list of your files will appear.

-If your source code file was Modified an M will appear before the filename.

-If an ?? appears before the filename, it must be added, so Type 2 and then enter the path and filename as it was displayed in the files list. Press enter after typing in the path/file.

Now, type 0 and Press the Enter key.

Another file list appears. Your file should be listed with an M in front of it.
If it has an ??, you can add all un-tracked files by typing yes and then Enter.
Otherwise, type no and press Enter.

Are you feature complete: Type yes and press Enter. So, it does the update.
Enter a commit message and press Enter.

Follow the instructions to do a Pull first.

If you SSH for git to work and have a password, enter it....

Follow the instructions to do a Push now.

If all worked out, the message: Super job! will be shown now press Enter to exit. That's it, all done.
I found, this gem while searching for code online: 
Bonus: GIT COLORS for BASH PROMPT: See link below: 
Scott Woods - Git Prompt 
Git Colors - Based on work by halbtuerke and lakiolen. Thanks, Scott...

Tuesday, September 19, 2017

.bash_aliases - Common Lazy Admin Stuff


# print this months calendar out
cal
# print date and time
# date +"%A, %B %-d, %Y"
#print OS + CPU
uname -rvp

# List these alias Commands, this file...
alias commands='nice -n 17 less ~/.bash_aliases'

#Check if Root
if [ $UID -ne 0 ]; then
    # This is not a root user: 
    echo "Welcome, " `whoami`
    echo "This is a protected system! All access is logged." 
    alias reboot='sudo reboot'
    alias upgrade='sudo apt-get upgrade'
else 
    # Wow, got root:  
    echo "You are logged in as an admin becareful! This is a restricted system, this will be logged."
    alias upgrade='apt-get upgrade'
fi

#cheat-sheet
chmod-cheat() {
echo "chmod =:"
echo "1 = execute only"
echo "2 = write only"
echo "3 = write and execute (1+2)"
echo "4 = read only"
echo "5 = read and execute (4+1)"
echo "6 = read and write (4+2)"
echo "7 = read and write and execute (4+2+1)"
echo "qmod =:"
echo "web) 0644"
echo "safe) 0640"
echo "sbin) 0110"
echo "bin) 0111"
echo "exe) 0111"
echo "+w) 0660"
echo "fullwrite) 0666" 
echo "readonly) 0440"
echo "+777) 777"
}
qmod() {
 if [ -e "$2" ]; then
   if [ -n "$1" ]; then
     if [ -d "$2" ] && [ "$3" == "-R" ]
    then
          OPTION="-R"
  else
          OPTION=""
     fi   
     case $1 in
      web) /bin/chmod $OPTION 0644 "$2" ;;
      safe) /bin/chmod $OPTION 0640 "$2" ;;
      sbin) /bin/chmod $OPTION 0110 "$2" ;;
      bin) /bin/chmod $OPTION 0111 "$2" ;;
      exe) /bin/chmod $OPTION 0111 "$2" ;;
      +w) /bin/chmod $OPTION 0660 "$2" ;;
      fullwrite) /bin/chmod $OPTION 0666 "$2" ;; 
      readonly) /bin/chmod $OPTION 0440 "$2" ;;
      +777) /bin/chmod $OPTION 777 "$2" ;;
      777) echo "are you sure? If so, do chmod +777 file" ;;
      *) /bin/chmod $OPTION $1 "$2" ;;
     esac   
   fi
 else   
   if [ ! -e "$1" ]; then
    echo qmod "$1" file/folder does not exists
   else
    chmod-cheat
   fi 
 fi    
}

#git
alias gs='git status'
alias gc='git commit -a -m'
alias mpull='git pull origin master'
alias mpush='git push origin master'
alias pull='git pull origin'
alias push='git push origin'
alias gb='git branch'
alias branch='git branch'
alias clone='git clone'
alias checkout='git checkout'
#alias gitolite='git clone gitolite:'

#tar
maketar() {
 if [ -e "$1" ]; then
  tar cvzf "$1.tgz" "$@"
 else
   if [ -e "$2" ]; then
    x="" 
    for var in "$@"
    do
      if [ -e "$var" ]; then
        x+=$var
        x+=" "
      fi  
    done
    tar cvzf "$1.tgz" $x
   else
    if [ -n "$1" ]; then
      tar cvzf "$1.tgz" *
    else
      tar cvzf all.tgz *
    fi    
   fi 
 fi
} 

bk() {
 tar cvzf "$1".$(date +%Y%m%d-%H%M%S).tgz "$1"
}

alias untar='tar xvf'
alias ungz='tar xvfz'

#RSYNC
alias backup="nice -n 17 rsync --progress -ravz"

#apt-get
alias agi='sudo apt-get install'
alias agr='sudo apt-get remove'
alias agu='sudo apt-get update'
alias acs='apt-cache search'

#programming
alias c='g++ -std=c++11'
alias c14='g++-4.9 -std=c++14 -pedantic -Wall -I /opt/boost_1_55_0'
alias boost='c++ -I /opt/boost_1_55_0'
# Free Basic Compiler
alias qb='fbc -lang qb '

#Networking
alias public-ip='dig +short myip.opendns.com @208.67.222.222 @208.67.220.220'
alias myip='/bin/ip -4 addr'
alias mymac='/sbin/ifconfig -a'
alias quickping='time ping -c 5'
alias fastping='ping -c 100 -i .250 -s .2'
# Lists all open UDP/TCP ports
alias ports='netstat -tulanp'

# Wake up remote PC/Sever
alias ipwake='/usr/bin/wakeonlan -i'
alias wake='echo "WakeOnLAN File with MAC and IP" && /usr/bin/wakeonlan -f'

# Firewall
alias ipt='sudo /sbin/iptables'
# Display all firewall rules
alias iptlist='sudo /sbin/iptables -L -n -v --line-numbers'
alias iptlistin='sudo /sbin/iptables -L INPUT -n -v --line-numbers'
alias iptlistout='sudo /sbin/iptables -L OUTPUT -n -v --line-numbers'
alias iptlistfw='sudo /sbin/iptables -L FORWARD -n -v --line-numbers'
alias firewall=iptlist

#More Networking
export LAN='eth0'
export WAN='eth1'
alias dnstop='dnstop -l 5 "$LAN"'
alias vnstat='vnstat -i "$LAN"'
alias iftop='iftop -i "$LAN"'
alias tcpdump='tcpdump -i "$LAN"'
alias ethtool='ethtool "$LAN"'

export SN=`netstat -nr | grep -m 1 -iE 'default|0.0.0.0' | awk '{print \$2}' | sed 's/\.[0-9]*$//' `
alias find-servers='nmap --top-ports 10 "$SN".*'
alias find-web-servers='nmap -p 80,443,8080  "$SN".*'
alias find-file-servers='nmap -p 137,138,139,445 "$SN".*'
alias find-ssh-servers='nmap -p 22 "$SN".*'
alias find-ftp-servers='nmap -p 21 "$SN".*'

# Get Wireless Status
alias iwconfig='iwconfig wlan0'
alias wifi=iwconfig

#Ping Default Gateway
export GW=`netstat -nr | grep -m 1 -iE 'default|0.0.0.0' | awk '{print $2}'`
alias check-intenet='ping -c 5 -i .250 -s .2 "$GW"'

#Reboot routers
rebootlinksys() {
 curl -u "admin:$2" "http://$1/setup.cgi?todo=reboot"
}

rebootnetgear() {
 wget --output-document=/dev/null --user="admin" --password="$2" "http://$1/setup.cgi?next_file=diag.htm&todo=reboot"
}

ssh-reboot() {
  if [ -n "$2" ]; then
    ssh "$1"@"$2" sudo -S /sbin/reboot
  else
    ssh "root@$1" /sbin/reboot
  fi  
}

# misc functions
function extract {
 if [ -z "$1" ]; then
    # display usage if no parameters given
    echo "Usage: extract ."
 else
    if [ -f $1 ] ; then
        NAME=${1%.*}
        case $1 in
          *.deb)       echo Installing deb package   ;;
          *.rpm)       echo Installing rpm package   ;;          
          *)           mkdir $NAME && cd $NAME       ;;
        esac

        case $1 in
          *.deb)       sudo nice -n 17 dpkg -i $1       ;;
          *.rpm)       sudo nice -n 17 rpm -ivh $1      ;;          
          *.tar.bz2)   nice -n 17 tar xvjf ../$1        ;;
          *.tar.gz)    nice -n 17 tar xvzf ../$1        ;;
          *.tar.xz)    nice -n 17 tar xvJf ../$1        ;;
          *.lzma)      nice -n 17 unlzma ../$1          ;;
          *.bz2)       nice -n 17 bunzip2 ../$1         ;;
          *.rar)       nice -n 17 unrar x -ad ../$1     ;;
          *.gz)        nice -n 17 gunzip ../$1          ;;
          *.tar)       nice -n 17 tar xvf ../$1         ;;
          *.tbz2)      nice -n 17 tar xvjf ../$1        ;;
          *.tgz)       nice -n 17 tar xvzf ../$1        ;;
          *.zip)       nice -n 17 unzip ../$1           ;;
          *.Z)         nice -n 17 uncompress ../$1      ;;
          *.7z)        nice -n 17 7z x ../$1            ;;
          *.xz)        nice -n 17 unxz ../$1            ;;
          *.exe)       nice -n 17 cabextract ../$1      ;;
          *)           echo "extract: '$1' - unknown archive method" ;;
        esac
    else
        echo "$1 - file does not exist"
    fi
fi
}

function fawk {
    first="awk '{print "
    last="}'"
    cmd="${first}\$${1}${last}"
    eval $cmd
}

# Is gzip working?
function is_gzip {
  curl -I -H 'Accept-Encoding: gzip,deflate' $1 |grep "Content-Encoding"
}

#misc linux
alias hg='history|grep'
alias changed-files='find . -mtime -30 | less'
search() {
  find . -name "$1" -print
}
match() {
  echo "usage: match search_for_pattern file/files" 
  grep -n "$@" | less
}
abc() {
  if [ -n "$2" ]; then
    sort "$1" | grep "$2"
  else
    sort "$1"
  fi  
}
short-asc() {
  abc "$@" | head
}
alias short='sed 100q'
view-long() {
  sed 500q $1 | less
}
save-long() {
  if [ -n "$2" ]; then
    sed 500q $1 > $2
  else
    echo "example: save-long in-file out-file"
  fi
}
head-log() {
  if [ -n "$2" ]; then
    head -n 2000 $1 > $2
  else
    head -n 2000 $1 | less
  fi
}
tail-log() {
  if [ -n "$2" ]; then
    tail -n 2000 $1 > $2
  else
    tail -n 2000 $1 | less
  fi
}  
alias cp='cp -iv'
alias mv='mv -iv'
alias rm='rm -I --preserve-root'
alias la='ls -alh'
mybackup() {
  backup $@ ~/MyBackups/
}
alias documents='cd ~/Documents'
alias downloads='cd ~/Downloads'
alias desktop='cd ~/Desktop'
alias music='cd ~/Music'
alias videos='cd ~/Videos'
alias photos='cd ~/Pictures'
alias cd.='pwd'
alias cd..='cd ..'
alias cd,,='cd ..'
alias ..='cd ..'
alias ,,='cd ..'
alias ...='cd ../..'
alias up2='cd ../..'
alias up3='cd ../../..'
alias up4='cd ../../../..'
alias n='nano'
g() {
  geany $1 &
}
alias e='exit'
alias bye='exit'
alias s='sudo -i'
mcd() {
    mkdir -p $1
    cd $1
}
link-file() {
  if [[ -n "$1" && -n "$2" && -f "$1" && ! -f "$2" ]]; then
    ln -s "$1" "$2"
  else
    echo "link /home/user/source_FILE /opt/new_link"  
  fi
}

link-dir() {
  if [[ -n "$1" && -n "$2" && -d "$1" && ! -f "$2" ]]; then
    ln -s "$1" "$2"
  else
    echo "link /home/user/source_DIR /opt/new_link"  
  fi
}
alias findblanks='sudo awk -F: '\''($2 == "") {print}'\'' /etc/shadow'
alias findrootusers='sudo awk -F: '\''($3 == "0") {print}'\'' /etc/passwd'
alias lock='gnome-screensaver-command --lock'
alias mounted='mount | column -t'
alias md='mkdir -p'
alias o='less'
# wget -c will resume getting a partially-downloaded file.
alias wget='wget -c'

#Maintance
alias cleantmp='find /tmp -atime +3 -exec rm -f {} ";"'

#Web
alias chrome='/opt/google/chrome/chrome'
#my default browser 
alias web=chrome

#CPU and Memory useage
# pass options to free  
alias meminfo='free -m -l -t'

#File Useage
# Disks and File System useage 
alias df='df -H'
# Disk Usage for a folder in useful sizes
alias du='du -ch'
alias disks=df
alias useage=du
alias home='echo "Please wait... Calculating Size of Home..." && du -s /home'
 
# get top process eating memory
alias psmem='ps auxf | sort -nr -k 4'
alias psmem10='ps auxf | sort -nr -k 4 | head -10'
 
# get top process eating cpu
alias pscpu='ps auxf | sort -nr -k 3'
alias pscpu10='ps auxf | sort -nr -k 3 | head -10'

# Get server cpu info 
alias cpuinfo='lscpu'

#Debug Web Server
alias errors=ap_errors
alias ap_errors='tail /var/log/apache2/error.log'
alias hh_errors='tail /var/log/hhvm/error.log'
alias ng_errors='tail /var/log/nginx/error.log'
# Get web server headers #
alias header='curl -I'
# Find out if remote server supports gzip / mod_deflate or not #
alias headerc='curl -I --compress'

# Controll Web Servers
alias a2='sudo service apache2 restart'
alias hh_restart='sudo service hhvm restart'
alias t7='sudo /etc/init.d/tomcat7 restart'
alias phpstatus='service php5-fpm status'
alias phpstart='service php5-fpm start'
alias ngreload='sudo /usr/sbin/nginx -s reload'
alias ngtest='sudo /usr/sbin/nginx -t'
alias lightyload='sudo /etc/init.d/lighttpd reload'
alias lightytest='sudo /usr/sbin/lighttpd -f /etc/lighttpd/lighttpd.conf -t'
alias httpdreload='sudo /usr/sbin/apachectl -k graceful'
alias httpdtest='sudo /usr/sbin/apachectl -t && /usr/sbin/apachectl -t -D DUMP_VHOSTS'

#Windows to linux
alias attrib='chmod'
alias chdir='cd'
alias copy='cp'
alias del='rm'
alias deltree='rm -r'
alias dir='/bin/ls $LS_OPTIONS --format=vertical'
alias edit='nano'
alias ff='whereis'
alias mem='top'
alias move='mv'

## You should use these on servers instead of default commands...!!
#set nice levels for common commands
alias ncfg='nice -n 2 ./configure'
alias nmake='nice -n 2 make'
alias nmakeinstall='sudo nice -n 2 make install'
alias ncp='nice -n 17 cp -iv'
alias nmv='nice -n 17 mv -iv'
alias nrm='nice -n 17 rm -I --preserve-root'
alias ncurl='nice -n 17 curl'
nmaketar() {
 if [ -e "$1" ]; then
  nice -n 17 tar cvzf "$1.tgz" "$@"
 else
   if [ -e "$2" ]; then
    x="" 
    for var in "$@"
    do
      if [ -e "$var" ]; then
        x+=$var
        x+=" "
      fi  
    done
    nice -n 17 tar cvzf "$1.tgz" $x
   else
    if [ -n "$1" ]; then
      nice -n 17 tar cvzf "$1.tgz" *
    else
      nice -n 17 tar cvzf all.tgz *
    fi    
   fi 
 fi
} 
alias ntar='nice -n 17 tar'
alias nungz='nice -n 17 tar xvfz'
alias nuntar='nice -n 17 tar xvf'
alias nl='nice -n 17 ls --color=auto -alh'
alias nn='nice -n 17 nano'
ng() {
  nice -n 17 geany $1 &
}
alias no='nice -n 17 less'
alias nless='nice -n 17 less'
alias ngrep='nice -n 17 grep --color=auto'
alias nhg='history | nice -n 17 grep --color=auto'
#RSYNC
alias nbackup="nice -n 2 rsync --progress -ravz"
alias nrsync="nice -n 2 rsync"
#apt-get
alias nagi='sudo nice -n 2 apt-get install'
alias nagr='sudo nice -n 2 apt-get remove'
alias nagu='sudo nice -n 2 apt-get update'
alias nacs='nice -n 2 apt-cache search'
#git
alias ngs='nice -n 17 git status'
alias ngc='nice -n 17 git commit -a -m'
alias nmpull='nice -n 17 git pull origin master'
alias nmpush='nice -n 17 git push origin master'
alias npull='nice -n 17 git pull origin'
alias npush='nice -n 17 git push origin'
alias ngb='nice -n 17 git branch'
alias nbranch='nice -n 17 git branch'
alias nclone='nice -n 17 git clone'
alias ncheckout='nice -n 17 git checkout'

# useage up 3 cd ../../..
up(){
  local d=""
  limit=$1
  for ((i=1 ; i <= limit ; i++))
    do
      d=$d/..
    done
  d=$(echo $d | sed 's/^\///')
  if [ -z "$d" ]; then
    d=..
  fi
  cd $d
}

gpull-and-push GIT Pull & Push Script


#!/bin/bash
clear
if [ -z "$1" ];  then
 /bin/echo "Please enter you GIT Folder"
 exit 1
else 
 cd "$1"
 /usr/bin/git status -s
 branch=$(git symbolic-ref --short -q HEAD)
 branch=${branch:-HEAD}
 /bin/echo "Did you see any files that you must first add using: git add file ?"
 /bin/echo "Please type: yes/no (then hit enter). yes will add the files, no will skip them."
 read safe
 if [ $safe = yes ]; then
  /usr/bin/git add --all .
 else 
  if [ $safe = no ]; then
   echo "Ok"
  else
   exit 1
  fi
 fi 
 /bin/echo "Are you feature complete and working?"
 /bin/echo "Please type: yes (then hit enter), to do a git pull/push to make $1 up to date!"
 read agree
 if [ $agree = yes ]; then 
  /bin/echo "Please enter your commit message now: What features are added/removed?"
  while :
  do
   read commit
   LEN=$(echo ${#commit})
   if [ $LEN -lt 5 ];  then
    /bin/echo "Please enter your a commit message! What did you work on?"
   else
    break
   fi 
  done
  /usr/bin/git commit -a -m "$commit"
  if [ $? -eq 0 ]; then
   /bin/echo "I applied your commit message, $commit"
  else
   /bin/echo "Opps"
   read -n 1 -p "Hit a key to abort!"
   exit 1
  fi
  /usr/bin/git status
  read -n 1 -p "Ready to pull in new code? Hit any key..."
  /usr/bin/git pull origin $branch
  if [ $? -eq 0 ]; then
   /bin/echo "done with pulling."
  else
   /bin/echo "Opps"
   read -n 1 -p "Hit a key to abort!"
   exit 1
  fi
  /bin/echo "Ready to save your work"
  read -n 1 -p "Press any key to continue..."
  /usr/bin/git push origin $branch
  if [ $? -eq 0 ]; then
   /bin/echo "Super job!"
  else
   /bin/echo "Opps"
   read -n 1 -p "Hit a key to abort!"
   exit 1
  fi
  #/bin/echo "Update Project?"
  #/bin/echo "Have you tested this yet? If working, type: yes (then hit enter)."
  # read worked
  #if [ $worked = yes ]; then
  # /usr/bin/ssh -t project "cd /home/bob/project; /usr/bin/git pull origin master"
  # /bin/echo "thanks"
  #fi
  read -n 1 -p "Press any key to exit"
  /bin/echo ""
  exit 0
 else
  /bin/echo "Skipped update..."
  read -n 1 -p "Press any key to continue..."
  /bin/echo ""
  exit 1
 fi
fi