Skip to content

Instantly share code, notes, and snippets.

@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;
@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()) {
(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 / 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}})))
@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-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 / 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 / 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 / gist:5880732
Last active September 15, 2018 01:22
WebSocket subprotocol and origin validation with HTTP Kit
(ns my.server
(:use org.httpkit.server
[clojure.string :only [split trim lower-case]])
(:import [org.httpkit.server AsyncChannel]))
(defn origin-match? [origin-re req]
(if-let [req-origin (get-in req [:headers "origin"])]
(re-matches origin-re req-origin)))
(defn rpc-url [path] (str "http://wamptutorial/rpc#" path))
(defn evt-url [path] (str "http://wamptutorial/event#" path))
(defn auth-secret [sess-id auth-key extra]
"secret-password") ; from database
(defn auth-permissions [sess-id auth-key}
; get permissions for this user
{:rpc {(rpc-url "echo") true}
:subscribe {(evt-url "chat") true}