Skip to content

Instantly share code, notes, and snippets.

@bencooling
Last active December 20, 2015 00:39
Show Gist options
  • Save bencooling/6042939 to your computer and use it in GitHub Desktop.
Save bencooling/6042939 to your computer and use it in GitHub Desktop.
shell scripts
@echo off
Rem Insert the path to your php executable in the line below!!
\wamp\bin\php\php5.2.9\php classGen.php
echo Writing new class file!
PAUSE
<?php
// config
$config= array(
'vis'=> array( 'public', 'protected', 'private' )
);
// class
class ClassGen{
public $className;
public $vis;
public $properties;
public function askClassName(){
fwrite(STDOUT, "Enter your class name:");
$this->className = trim(fgets(STDIN));
}
public function askVis(){
$vis_list="";
global $config;
foreach($config['vis'] as $k=>$v){
$vis_list.= "\n$k:$v";
}
fwrite(STDOUT, "Enter the visibility of the class properties:$vis_list\n");
$i= trim(fgets(STDIN));
$accept= array(0,1,2);
if ( in_array($i, $accept) ) {
$this->vis = $config['vis'][$i];
}
else {
fwrite(STDOUT, "Please enter either 0 1 or 2:\n");
$this->askVis();
}
}
public function askProperties(){
fwrite(STDOUT, "Enter a comma seperated list of properties for the class:\n");
$this->properties = trim(fgets(STDIN));
}
public function writeClass(){
$className= ucfirst($this->className);
$fh= fopen($className.'.class.php', "w");
fwrite($fh,"<?php \n");
fwrite($fh, "class $className{\n\n");
if (strpos(',', $this->properties)!==-1) $arrProperties= explode(',', $this->properties);
else {
// Make sure we just get first valid word if incorrectly formatted string is provided
preg_match('/(\b\w+\b)/', $this->properties, $matches);
$arrProperties= array( $matches[0] );
}
$arrProperties = array_map('strtolower', $arrProperties); // make sure all lowercase
$arrProperties = array_map('trim', $arrProperties); // trim whitespace
foreach($arrProperties as $k=>$v){
fwrite($fh, "\t".$this->vis." ".$v.";\n");
}
fwrite($fh, "\n");
foreach($arrProperties as $k=>$v){
// getter
fwrite($fh, "\tpublic function get".ucfirst($v)."(){\n");
fwrite($fh, "\t\treturn \$this->".$v.";\n");
fwrite($fh, "\t}\n");
// setter
fwrite($fh, "\tpublic function set".ucfirst($v)."(\$$v){\n");
fwrite($fh, "\t\t\$this->".$v."=$v;\n");
fwrite($fh, "\t}\n");
}
fwrite($fh, "\n}\n");
fwrite($fh,"?>");
fclose($fh);
}
}
$myClassGen= new ClassGen();
$myClassGen->askClassName();
fwrite(STDOUT, "Class equals: $myClassGen->className\n");
$myClassGen->askVis();
fwrite(STDOUT, "Vis equals: $myClassGen->vis\n");
$myClassGen->askProperties();
$myClassGen->writeClass();
?>
#!/bin/bash
#
# Update to Latest
# Script to run to update vendor files: bourbon, jquery, requrejs etc
# Just in case github repo is out of sync
# Variables
# -------------------------
# Path that script was executed from
DIR="$( cd "$( dirname "$0" )" && pwd )"
# normalize.css
# -------------------------
curl https://raw.github.com/necolas/normalize.css/master/normalize.css > "$DIR/style/normalize.scss"
# Bourbon
# -------------------------
rm -r "$DIR/style/bourbon"
cd "$DIR/style"; bourbon install;
# jquery.js
# -------------------------
curl http://code.jquery.com/jquery-latest.js > "$DIR/script/jquery.js"
# requirejs.js
# -------------------------
curl https://raw.github.com/requirejs/text/latest/text.js > "$DIR/script/jquery.js"
echo "Completed"

shell scripts

Various shell scripts

Class Generator

Includes the following files for creating class files in Windows environment:

  • classGenerator.php
  • classGenerator.bat
  • downloadLatestFiles.sh
#!/bin/bash
#===================#
# VARIABLES #
#===================#
##
# @SSH_USER: User to login to server
# @SSH_DOMAIN: Domain to SSH into
#
SSH_USER="bencooling"
SSH_DOMAIN="bcooling.com.au"
SSH_PORT="2966"
ssh -C -p ${SSH_PORT} ${SSH_USER}@${SSH_DOMAIN} "sudo su bcooling"
# ssh -C -p ${SSH_PORT} ${SSH_USER}@${SSH_DOMAIN} <<EOT
# sudo su bcooling
# whoami > ~/whoami.txt
# EOT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment