Skip to content

Instantly share code, notes, and snippets.

@paulwsmith
paulwsmith / ApiResourceComponent.php
Last active January 14, 2016 08:29
returnsFieldsAsAttributes.php
public function returnsFieldsAsAttributes() {
if (empty($this->_result) || empty($this->_field_map)) {
return $this->_result;
}
$field_map = $this->_field_map;
$this->withFieldMap();
$this->forModel();
<?php
/**
* CakePHP 2.x -- add this code to a controller and then access the controller's route from the browser.
* This allows you to trigger shells through the browser, so that you can use xdebug if it cannot be accessed
* through the command line
*/
App::uses('ShellDispatcher', 'Console');
public function index() {
angular.module('wizehive.resources', ['ngResource', 'wizehive.auth'])
.factory('Data', ['$rootScope', '$http', '$q', '$resource', 'Auth', 'PluginEvents', function($rootScope, $http, $q, $resource, Auth, PluginEvents) {
var _apiBaseUrl = wizehive.config('constants').API_URL || '';
/* ... */
function beforeFilter(params) {
params = _flattenObject(params);
@paulwsmith
paulwsmith / appRunner.js
Created June 11, 2015 15:56
Local plugin runner exploration
/* DO NOT MODIFY THIS FILE! IT'S FOR LOCAL USE ONLY! */
app.uses(function(req, resp, next) {
var httpRequest = require('httpRequest');
httpRequest.setAccessToken(req.headers.accessToken);
delete req.headers.accessToken;
var eventData = {};
eventData.request = {
headers: req.getHeaders(),
znRecordOverlay.open({
onSubmit: function(submittedData, onComplete) {
var newRecord = {};
angular.extend(newRecord, submittedData);
console.log(newRecord.id); // error
$scope.recordList.push(submittedData);
onComplete.then(function(serverData) {
// each onSave and "included" onComplete promise are connected by being in closure together
// you can have as many as you want and they won't interact with each other
angular.extend(newRecord, serverData);
/**
* Plugin many lines 2 Controller
*/
plugin.controller('manyLines2Cntl', ['$scope', function ($scope) {
$scope.text = 'Hello World!';
var data = [
'Lorem ipsum dolor sit amet, consectetur adipiscing elit.',
'Duis a lorem id felis hendrerit facilisis.',
@paulwsmith
paulwsmith / znDebug
Created November 20, 2014 18:06
Zengine debug bookmarklet
javascript:(function(){var i=$('body').injector().get;window.$rootScope=i('$rootScope');window.Data=i('Data');window.getService=i;console.log('Services set in console');})()
@paulwsmith
paulwsmith / globals.js
Created September 15, 2014 15:44
JS global variable access
myGlobal = 'I am accessible!'; // global var
(function(window) {
console.log('Without clearing anything');
console.log(window.myGlobal); // 'I am accessible!'
console.log(myGlobal); // 'I am accessible!'
})(window);
(function(window) {
angular.module('wizehive.services')
.service('PluginEvents', ['$rootScope', '$timeout', function($rootScope, $timeout) {
var scopes = {
// This would be set up dynamically, maybe by plugin directive?
'action-panel-top': $rootScope.$new(false),
'top-nav': $rootScope.$new(false)
};
return function(location) {
<?php
require_once 'curl' . DIRECTORY_SEPARATOR . 'curl.php';
$Curl = new Curl();
// This is called once, after we get a code back
if (!empty($_GET['code'])) {
// Make sure there wasn't an error authenticating
if (!empty($_GET['error'])) {