Skip to content

Instantly share code, notes, and snippets.

@cgmartin
cgmartin / rpc-server.clj
Created June 24, 2013 05:41
clj-wamp tutorial source snippets
(defn rpc-url [path] (str "http://wamptutorial/rpc#" path))
(defn wamp-handler
; ...
(clj-wamp/http-kit-handler channel
{:on-call {(rpc-url "echo") identity}})
; ...
@cgmartin
cgmartin / rpc-client.js
Last active December 18, 2015 21:29
clj-wamp tutorial source snippets
var sess;
ab.connect(
// ...
function (session) { // Connection callback
sess = session;
sess.prefix("rpc", "http://wamptutorial/rpc#");
},
// ...
);
@cgmartin
cgmartin / server-pubsub.clj
Last active December 18, 2015 21:29
clj-wamp tutorial source snippets
(defn evt-url [path] (str "http://wamptutorial/event#" path))
(defn wamp-handler
; ...
(clj-wamp/http-kit-handler channel
{:on-subscribe {(evt-url "chat") true}
:on-publish {(evt-url "chat") true}})
; ...
@cgmartin
cgmartin / client-pubsub.js
Last active December 18, 2015 21:29
clj-wamp tutorial source snippets
var sess;
ab.connect(
// ...
function (session) { // Connection callback
sess = session;
sess.prefix("event", "http://wamptutorial/event#");
sess.subscribe("event:chat", onChatEvent);
},
// ...
@cgmartin
cgmartin / server-example.clj
Last active December 18, 2015 21:19
clj-wamp tutorial source snippets
(defn wamp-handler [req]
(wamp/with-channel-validation req channel (:ws-origins-re (conf))
(wamp/http-kit-handler channel
{:on-open on-open
:on-close on-close
:on-call {(rpc-url "echo") identity
:on-before on-before-call}
:on-subscribe {(evt-url "chat") true}
:on-publish {(evt-url "chat") true
:on-after on-publish}})))
(ns clj-wamp-example
(:require [org.httpkit.server :as http-kit]
[clj-wamp.server :as wamp]))
; Topic URIs
(defn rpc-url [path] (str "http://clj-wamp-example/api#" path))
(defn evt-url [path] (str "http://clj-wamp-example/event#" path))
(defn wamp-websocket-handler [req]
(http-kit/with-channel req channel
@cgmartin
cgmartin / Controller.php
Created February 20, 2013 18:37
File Count test
public function transferAction()
{
$upload = new \Zend\File\Transfer\Transfer();
$upload->setDestination('./data/tmpuploads/');
$upload->addValidator('Extension', false, array('extension' => array('jpg','jpeg','png')));
$upload->addValidator('Count', false, array('max' => 1));
$rtn = array('success' => null);
if ($this->getRequest()->isPost()) {
@cgmartin
cgmartin / IndexController.php
Created February 20, 2013 16:51
Zend\Transfer functional test
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/ZendSkeletonApplication for the canonical source repository
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace Application\Controller;
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/ZendSkeletonApplication for the canonical source repository
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace Application\Controller;
<?php
$this->navigation()->getPluginManager()->setAllowOverride(true)->setInvokableClass('menu', '\My\Helper');
// In Module.php
public function getViewHelperConfig()
{
return array(
// Change the Navigation View Helper plugins for ALL modules
'initializers' => array(