Skip to content

Instantly share code, notes, and snippets.

@joegreen88
joegreen88 / git-release-function.sh
Last active May 8, 2018 07:50
A bash function to create a new tag and push it to remote origin within a git repository
# Tag a new release from current branch and push the tag up to origin
# Specify a semver release type of patch, minor or major.
# Usage: git-release patch|minor|major [--force]
git-release() {
type="$1"
if [ "$type" == "patch" ] || [ "$type" == "minor" ] || [ "$type" == "major" ] ;then
git fetch origin --tags
tags="$(git tag --sort version:refname)"
latest="none"
while read tag; do
@joegreen88
joegreen88 / respondAJAX
Created April 19, 2013 10:30
Switch to JSON response in Zend Framework controller. Great for actions which accept XMLHttpRequests.
/**
* JSON response to an AJAX call
* return $success allows us to pass through result of some action without _respondAJAX() getting in the way, ie $result = $this->_respondAJAX($some->action());
*/
protected function _respondAJAX($success=false, $data=null, $errors=null)
{
$this->_helper->viewRenderer->setNoRender(true);
$this->_helper->layout->disableLayout(true);
$this->getResponse()->setHeader('Content-type', 'application/json');
$this->view->clearVars();
@joegreen88
joegreen88 / cleanEmptyRows
Created April 19, 2013 10:15
Filter empty rows out of a Smrtr_DataGrid instance.
<?php
$grid = $grid->filterRows(function($key, $label, $row){
return array_reduce($row, function(&$result, $item){
$result = is_null($item) ? $result : true;
}, false);
});
?>
@joegreen88
joegreen88 / commandLineRouter.php
Created November 27, 2012 21:35
Route command line options foo bar to barAction on fooController in zend framework
// in Bootstrap.php
if (PHP_SAPI == 'cli')
{
$front = $this->getResource('frontcontroller');
$front->setParam('disableOutputBuffering', true);
$front->setRouter( new Application_Model_RouterCLI() );
$front->setRequest( new Zend_Controller_Request_Simple() );
}
// the router
@joegreen88
joegreen88 / subroute.php
Created November 24, 2012 16:03
Route static subdomains to controllers in zend framework
if (PHP_SAPI != 'cli') //subdomain routing
{
$domainname = $this->getOption('domainname');
$subdomains = $this->getOption('subdomains');
$router = $this->bootstrap('frontController')->getResource('frontController')->getRouter();
// routes for mainsite (default router is added)
$wwwRoute = new Zend_Controller_Router_Route_Hostname(
$domainname,
array('module' => 'default')