Manage background tasks with PHP-Resque and Supervisor

PHP-Resque, the PHP equivalent to Ruby’s really nice background process runner is a great way to execute long running PHP processes. Supervisor is a python-based process control system, essentially it’s a convenient way to manage custom system processes you need to handle. Combining the two to manage long running PHP jobs makes a lot of sense but it takes a little bit of work to get them talking. Once you’ve gotten PHP-Resque installed on your project, you’ve added items to your queue and written the workers to handle the background tasks. You’ll need to plug PHP-Resque into supervisor. Here’s a sample config file I used to manage php resque queues within Yii projects but it should work with anything that’s using php-resque. ...

July 3, 2014 · Shane Dowling

Simple API Mocking with Guzzle and Charles

If you’ve ever had to try unit test code that’s dependent on external services, you’ll know the pain of trying to mock-up fake API requests by hand. It’s painful to setup and painful to maintain, this little tutorial attempts to make the whole process as easy as possible. Step 1: Capturing a live set of API requests. So firstly download and install Charles Web Proxy. Here’s a good description of what Charles can do from their site. ...

June 26, 2014 · Shane Dowling

SugarCRM — Permissions Script

I use salt quite extensively to deploy SugarCRM installs and I wanted a scriptable way to setup the correct permissions for Sugar running on a linux box. This script is based on the Sugar documentation and this handy post here. Simply fill in your apache user details and the path to the Sugar install and you’re away. #!/bin/bash APACHEUSER='www-data:www-data' SUGARPATH='/var/www/sugarcrm' find -P $SUGARPATH/ -type d -exec chmod 755 {} \\; find -P $SUGARPATH/ -type f -exec chmod 644 {} \\; find -P $SUGARPATH/ -name *.js -exec chmod 755 {} \\; chmod 664 $SUGARPATH/config.php chmod 664 $SUGARPATH/config_override.php chmod 664 $SUGARPATH/sugarcrm.log find -P $SUGARPATH/cache -type d -exec chmod 775 {} \\; find -P $SUGARPATH/custom -type d -exec chmod 775 {} \\; find -P $SUGARPATH/data -type d -exec chmod 775 {} \\; find -P $SUGARPATH/modules -type d -exec chmod 775 {} \\; find -P $SUGARPATH/include -type d -exec chmod 775 {} \\; find -P $SUGARPATH/upload -type d -exec chmod 775 {} \\; find -P $SUGARPATH/cache -type f -exec chmod 664 {} \\; find -P $SUGARPATH/custom -type f -exec chmod 664 {} \\; find -P $SUGARPATH/data -type f -exec chmod 664 {} \\; find -P $SUGARPATH/modules -type f -exec chmod 664 {} \\; find -P $SUGARPATH/include -type f -exec chmod 664 {} \\; find -P $SUGARPATH/upload -type f -exec chmod 664 {} \\; chown -R $APACHEUSER $SUGARPATH And the salt config to get this running. ...

June 21, 2014 · Shane Dowling

Quick Salt Minion Setup

I find myself setting up salt minions a LOT. So I figured I’d write down the steps in this concise format. On the minion sudo add-apt-repository ppa:saltstack/salt sudo apt-get update && sudo apt-get install salt-minion sudo echo ' salt' >> /etc/hosts //Or whatever the salt master is sudo salt-call -l debug state.highstate Then on the master sudo salt-key -L sudo salt-key -a Then back on the minion sudo salt-call -l debug state.highstate ...

June 12, 2014 · Shane Dowling

SugarCRM 7 — Hiding subpanels based on specific criteria

The new Sugar subpanels look great but they do take up quite a lot space, without any ability to remove Subpanels via studio I’ve had to come up with a few ways to hide them. Note: Original Props go to Robin Larsson who wrote the original on the Sugar Community. What Robin’s code does is essentially hide fields based on a specific value within a record, I didn’t really need that ability much so I’ve altered his code based on use cases I’ve come across. ...

June 12, 2014 · Shane Dowling

Super simple folder backup one-liner

I needed a simple cron job, that just took backups of my project folders, should the worst happen to my laptop. Google brought up nothing obvious, so I figured I’d share it here. tar zcvf /tmp/snap.tgz ~/Projects && rsync /tmp/snap.tgz user@remotebox:/home/backups/snap_`date +%F_%T`.tgz && rm /tmp/snap.tgz Okay, I’ll admit it’s a bit of a long one-liner.

June 6, 2014 · Shane Dowling

SugarCRM 7 — Adding a custom column to a list

This is the SugarCRM 7 equivalent to this post here, because Sugar has dropped the process record logic hook, we need to come up with a new solution. Here’s how you can add a new column to a list view, I have to admit this is one of the really powerful additions to SugarCRM 7, no more crazy config files or hacks to try cheat your data in. By leveraging javascript events with a decent restful API you can come up with some really nice solutions, with lots of hooks to do custom things. Once you see the difference in implementation you’ll see why I’m so pleased. ...

May 22, 2014 · Shane Dowling

SugarCRM 7 — Adding an action to the listview

There doesn’t appear to be a documented way to do this but in SugarCRM 7 this is how I’ve added actions to the listview. For this example it’s showing how to add a button to an animal module, which adds the animal to a related circus event. 1. Adding thebutton This first thing you need to do is copy the global recordlist.php file into your module and create a custom recordlist.php which overrides the existing one. You can copy the base one SugarCRM has or simply take this file below and alter the add_to_circus button. Note the addtocirus:fire action, we will create javascript code that is called when this event is fired. This code should go into custom/module/animals/clients/base/views/recordlist/recordlist.php ...

May 18, 2014 · Shane Dowling

Find My Run — My first iPhone app

It’s a pretty basic app that lists the ten nearest running events in your area. There was a few new pieces of tech(for me) involved. The app was built with Appcelerator’s Alloy framework, which I must admit I quite like for rapid development of cross platform mobile apps(hopefully an Android version shouldn’t be too far behind). The API that drives it was build with Python, Flask, MongoDB and hosted with Heroku, also great tech for getting something out quickly. I’m hoping to improve the app as time goes on, but I have another idea I’m due to implement first… ...

May 17, 2014 · Shane Dowling

Owning Your Data — Replacing Dropbox

Dropbox as late has come under a fair bit of fire. They’ve added DMCA takedowns to personal folders, scan/open personal files and have appointed Condelleza Rice as a member of their board of directors. Which has kicked off quite a bit of backlash including a #dropdropbox tag that’s gaining popularity. Seems like an ideal time to start owning your data, dropping Dropbox and moving to your own hosted alternative. What I’m suggesting is up for a bit of debate, instead of using a hosted service like Dropbox, I use a tool called BitTorrent Sync to sync my documents for my laptops/tablets to my own personal server that acts as my file storage. This means that no files are transmitted to server I don’t have full root control of. There is, however a downside. Bit-Torrent Sync isn’t open source, which is why it won’t be recommended on Prism Break and understandably so. The team are looking at open sourcing it, but that could be some time before it’s decided. ...

April 24, 2014 · Shane Dowling