Skip to content

Instantly share code, notes, and snippets.

View settermjd's full-sized avatar

Matthew Setter settermjd

View GitHub Profile
@settermjd
settermjd / select-count.php
Created December 16, 2013 04:20
An example of using an SQL Expression in Zend\Db\Sql
/**
* First construct the Select object for the SQL query to run
*/
$select = new Select('tblusers');
$select->columns(array(
"recordCount" => new \Zend\Db\Sql\Expression("COUNT(*)")
));
/**
* Then execute the query, retrieving the first record, if available
@settermjd
settermjd / gist:8430918
Created January 15, 2014 04:46
A Zend Form created via annotations, modelling a very simple user record.
<?php
namespace MyApplication\Form;
use Zend\Form\Annotation;
/**
* @Annotation\Name("user")
* @Annotation\Hydrator("Zend\Stdlib\Hydrator\ObjectProperty")
*/
@settermjd
settermjd / compact-child-routes
Created April 2, 2014 14:37
Simple example of using child routes, using the Segment type, to keep a routing table in Zend Framework 2 simple and compact. For more information, check out http://www.masterzendframework.com/tutorial/child-and-segment-routes.
return array(
'router' => array(
'routes' => array(
'forecaster' => array(
'type' => 'Literal',
'options' => array(
'route' => '/forecaster',
'defaults' => array(
'__NAMESPACE__' => 'Forecaster\Controller',
'controller' => 'Forecaster',
// IndexControllerFactory.php
namespace YourModule\Controller\Factory;
use Zend\ServiceManager\FactoryInterface,
Zend\ServiceManager\ServiceLocatorInterface,
Zend\ServiceManager\Exception\ServiceNotCreatedException,
YourModule\Controller\IndexController;
class IndexControllerFactory implements FactoryInterface
{
@settermjd
settermjd / CustomSelectElementWithFormElementManager.php
Created April 22, 2014 12:27
A simple example of creating a custom select element, using the FormElementManager to handle the external dependencies.
<?php
/**
* Define the custom form element
*/
namespace Forecaster\Form\Element;
use Zend\Form\Element\Select;
use Zend\InputFilter\InputProviderInterface;
use Zend\Validator\Db\RecordExists;
use Zend\ServiceManager\ServiceLocatorAwareInterface;
@settermjd
settermjd / nginx owncloud config
Created September 3, 2014 09:34
A configuration of nginx for ownCloud (doesn't quite work yet)
server {
listen 80;
server_name owncloud.app
return 301 https://$server_name$request_uri; # enforce https
}
server {
listen 443 ssl;
server_name owncloud.app;
root /home/vagrant/owncloud;
// The following is a route to simplify getting started creating
// new controllers and actions without needing to create a new
// module. Simply drop new controllers in, and you can access them
// using the path /application/:controller/:action
'application' => array(
'type' => 'Literal',
'options' => array(
'route' => '/application',
'defaults' => array(
'__NAMESPACE__' => 'Application\Controller',
@settermjd
settermjd / gist:b9f4c875c252c587e737
Created February 26, 2015 12:15
Attempting to know if the following examples are effectively the same thing
/**
* Are these two examples the same, with the second just being more verbose?
*/
import static spark.Spark.*;
public class HelloWorld {
public static void main(String[] args) {
get("/hello", (req, res) -> "Hello World");
}
@settermjd
settermjd / spark-service
Created March 2, 2015 10:40
A simple chkconfig script to manage starting and stopping the Maven/Jetty server, which supports a SparkJava application
#! /bin/bash
#
# spark-service Start/Stop the Maven Jetty process
#
# chkconfig: 235 90 60
# description: This will manage the starting and stopping of the Maven/Jetty
# server which will render the SparkJava application. It's
# rather simple, so don't expect miracles of it.
#
@settermjd
settermjd / query-with-winston.sh
Created March 31, 2015 14:44
Querying with Winston
node winston.query.js | tr "[{:,'" ' ' | tr -s " " | awk '/country/ { print $2 }' | sort | uniq | wc -l | tr -s " "