Skip to content

Instantly share code, notes, and snippets.

@tom--
tom-- / Vagrantfile
Last active August 29, 2015 13:56
Two stage bootstrap of a Vagrant/Ansible provisioning environment to get rid of the insecure vagrant user account.
require 'yaml'
$ansible_vars = YAML.load_file('group_vars/all')
Vagrant.configure("2") do |config|
config.vm.box = "precise64"
config.vm.network :public_network
if ENV['FIRSTRUN'] != 'true'
config.vm.synced_folder ".", "/home/www"
config.ssh.username = $ansible_vars['unpriv_user']
@tom--
tom-- / i18nStrings.php
Created March 7, 2014 19:07
i18n strings
<?php
$i18nStrings = array(
'Iñtërnâtiônàlizætiøn',
'החמאס: רוצים להשלים את עסקת שליט במהירות האפשרית',
'ايران لا ترى تغييرا في الموقف الأمريكي',
'独・米で死傷者を出した銃の乱射事件',
'國會預算處公布驚人的赤字數據後',
'이며 세계 경제 회복에 걸림돌이 되고 있다',
'В дагестанском лесном массиве южнее села Какашура',
@tom--
tom-- / .borisrc
Created July 19, 2014 15:56
Start the wonderful Boris PHP REPL (https://github.com/d11wtq/boris) with Yii2. Handy for trying things out. Both files go in my home directory
<?php
require __DIR__ . '/startYii2.php';
$boris->setPrompt('yii2> ');
@tom--
tom-- / Gluster repl node replacement.md
Last active August 29, 2015 14:04
Replication node replacement

In a replication cluster, one of the nodes fails. I replace it with a new machine with the same hostname and address as the failed node. Then, with glusterd stopped on the replacement and running on the survivors

  • Get UUID of failed node from /var/lib/glusterd/peers on one of the survivors
  • Give it to the replacement node by putting it in /var/lib/glusterd/glusterd.info
  • Start glusterd on the replacement
  • On replacement, peer probe one of the survivors
  • Restart glusterd on replacement
@tom--
tom-- / MVC or not.md
Last active August 29, 2015 14:06
Will Yii show down your web site?

Will Yii slow down your web site?

The following question appeared out of the blue in #yii on Freenode in September 2014:

hi i have started working on yii framework... and other pople have been continuously telling me that its a bad decision and using yii will slow down the site and performance will not be good, better go for core php...any of your thoughts will be great help..cheers

How much penalty is there in using an MVC framework such as Yii?

There is no way to really answer the question because it depends so heavily on the specific application, the technologies involved and their deployment. Plenty of attempts have been made to benchmark different MVCs but the results are usually perfectly irrelevant to any given application. It would be a foolish mistake to think that data from, for example, TechEmpower's Web Framework Benchmarks would predict relative performance of your web site.

  • Modules are for sub-applications, reusable across projects. rights is a fairly good example.
  • Modules are not just a way of organizing your code into directories and don’t work well for that purpose.
  • User management doesn’t easily fit in a module because it is usually coupled to application business logic.
  • For the same reason, user management does not easily abstract into any kind of extension or into the framework APIs.
  • So you have to implement user management yourself and the right place is in the main app, just like yii2-app-advanced currently demonstrates.
  • The best you can do to abstract parts of the user management functionality into reusable code is to put some of the functionality into extension classes as nineinchnick/yii2-usr does.

I've had it up to here with the phony neo-romanticism of "epic" bike rides.

It started, as I recall it, with Rapha's monochrome marketing images of beautiful young men riding bikes and drinking black coffee in over-understated euro-chic clothing and without helmets, which spoil the look. The presentation always came with some implied or overt association with the history of pro bike racing and the heroism and torment of long hard bike rides.

The monochrome photography has become a mark of the genre. Its canonical form is film of Paris-Roubaix with soundtrack replaced by plaintive, soulful music to express the, passion and suffering, plenty of slow motion, maybe some amped-up contrast, images of muddy-faced cyclists, many of them disconsolate at the side of the road, out of the race due to a crash or equipment failure. The correspondence with Wagner or ETA Hoffmann disturbing: bombast, bogus mythology, Ach Weh, escapism and all that incoherent rot.

It quickly became—to what extent by clever engineering, I

@tom--
tom-- / revealing-module1.php
Last active August 29, 2015 14:15
Can PHP's so-called "closures" do any real closure work, like a revealing module? http://addyosmani.com/resources/essentialjsdesignpatterns/book/#revealingmodulepatternjavascript
<?php
function constructTotalizer() {
$privateTotal = 0;
$privateAddTotal = function ($n) use (&$privateTotal) {
$privateTotal += $n;
};
$publicAddTotal = function ($n) use ($privateAddTotal) {
@tom--
tom-- / gist:14864ce73c2a70d132bd
Last active August 29, 2015 14:15
Another Yii FAQ

Question: "I would like to know if it good idea to use Yii for developing..."

First, are you sure that:

  1. A server-side webapp is what's needed?
  2. MVC is the right architecture for the requirements and not, say, CMS?
  3. PHP is suitable for your situation?

If yes to all then Yii might work well for you and is worth considering. Start reading the user guide and take the demo app for a test drive. If you like it then you may be getting closer to an answer to the original question. If not then there are alternatives for you to try.

Yii 2 basic vs. advanced apps

The names of the two demo apps, Basic and Advanced, can be unhelpful. Many people end up choosing advanced just because of the name even though basic would suit them better.

The key differences are:

  1. Advanced has a complex system of configuration. It is designed so that a team of developers can work together on a project keeping everything, including app config, in VCS but each developer can customize their own config for development, testing and other environments.

    This configuration arrangement can be confusing and is often unnecessary. If you are working alone, you'd probably want to avoid it.