Skip to content

Instantly share code, notes, and snippets.

View acorncom's full-sized avatar

David Baker acorncom

View GitHub Profile
$items = array();
foreach($_POST['PO_LineItems'] as $item) {
$model = new PO_LineItem;
$model->setAttributes($item);
}
$poModel->LineItems = $items;
if($poModel->withRelated(true,array('LineItems'))) {
// everything is saved and we're ok
<?php
private $_browser;
private $_objMobileDetect;

public function init()
{
...
}
public setBrowser(Browscap $browser) {};
public function getBrowser() {
if(!isset($this->_browser)) {
$objBrowserCap = new \phpbrowscap\Browscap($this->cachePath);
@acorncom
acorncom / fracToDeci.js
Last active August 29, 2015 14:00 — forked from drifterz28/fracToDeci.js
Updated to allow full whole numbers and then a fraction
function toDeci(fraction) {
var result,wholeNum=0, frac, deci=0;
if(fraction.search('/') >=0){
if(fraction.search('-') > 0){
var wholeNum = fraction.split('-');
frac = wholeNum[1];
wholeNum = parseInt(wholeNum,10);
}else if(fraction.search(' ') > 0){
var wholeNum = fraction.split(' ');
fraction = wholeNum[1];

FiniteStateMachine Trait

Add a DSL to the PHP Finite package, borrowed from the Ruby StateMachine gem.

Usage

In your Stateful Class, add the stateMachineConfig() method and call initStateMachine() method at initialization (__contruct() method).

Example

namespace common\components;
use \yii\web\UrlManager as BaseUrlManager;
class UrlManager extends BaseUrlManager {
protected $choice;
public function init() {
Component::init();
@acorncom
acorncom / Controller or component
Last active August 29, 2015 14:20
Prototype of using Laravel Illuminate/queue inside of a Yii2 app
<?php
/* Note that the class and methods are prototype code, not copy/paste code
*
* However, the actual code in the action has been tested with a Yii2 app
*
*/
class QueueComponent extends Component {
public function actionTest() {
$sync = new \Illuminate\Queue\SyncQueue;
import Ember from 'ember';
export default Ember.Controller.extend({
appName:'Ember Twiddle'
});
@acorncom
acorncom / application.controller.js
Created September 29, 2015 18:28
potential-template-bug?
import Ember from 'ember';
export default Ember.Controller.extend({
appName:'Ember Twiddle',
creativeFields: [
{name: 'Yehuda'},
{name: 'Tom' },
{name: 'Trek' }
]
@acorncom
acorncom / application.controller.js
Last active October 15, 2015 19:31
testing twiddle
import Ember from 'ember';
export default Ember.Controller.extend({
appName:'Ember Twiddle'
});
@acorncom
acorncom / gist:a2f7757b7bf1f2f83161
Created November 4, 2015 16:44
SFTP Only access using OpenSSH with ChrootDirectory
Restricted SFTP-only access to a single directory using OpenSSH 4.9+
Edit ```/etc/ssh/sshd_config```
```
Match Group sftp-users
# Force the connection to use SFTP and chroot to the required directory.
ForceCommand internal-sftp
ChrootDirectory /home/sftp-users
# Disable tunneling, authentication agent, TCP and X11 forwarding.