Skip to content

Instantly share code, notes, and snippets.

@tom--
tom-- / MyDbCriteria.php
Last active December 30, 2015 20:19
MyDbCriteria adds prefix match searching to Yii’s CDbCriteria
<?php
class MyDbCriteria extends CDbCriteria
{
/**
* Adds a prefix match comparison to the {@link CDbCriteria::condition} property.
* The search condition is of the form
* - "column LIKE 'value%'", or
* - "column NOT LIKE 'value%'"
* depending onthe $like parameter.
@tom--
tom-- / cubrid join queries.txt
Created December 26, 2013 14:13
#cubrid discussion about join queries. see http://thefsb.tumblr.com/post/50437998370/
09:40 Topic is CUBRID Open source database highly optimized for Web applications || http://www.cubrid.org || CUBRID manual http://www.cubrid.org/manual/841/en || For questions also see: http://www.cubrid.org/questions
09:40 Set by eusto on July 19, 2012 11:31:26 AM EDT
09:40 Mode is +cnt
10:48 tom[]: not really a cubrid q but since the peeps here are so clever: http://thefsb.tumblr.com/post/50437998370
10:49 tom[]: How to get query results in normal form from a schema in normal form?
10:52 @rimio: tom[]: the guy likes to emulate a planner :)
10:53 tom[]: the guy being me :P
10:53 @rimio: :))
10:53 tom[]: isn't this an old question in SQL databases?
10:54 @rimio: might be, dunno
@tom--
tom-- / bash_prompt_fancy.sh
Last active June 8, 2018 23:54
A fancy bash prompt. Put it in your .bashrc
red=$(tput setaf 1)
green=$(tput setaf 2)
yellow=$(tput setaf 3)
bold=$(tput bold)
dim=$(tput dim)
off=$(tput sgr0)
thumb () {
case $1 in
0) printf "\xF0\x9F\x91\x8d" ;;
*) printf "\xF0\x9F\x91\x8e $red($1)$off" ;;
@tom--
tom-- / Generic Colouriser php
Created January 14, 2014 16:49
Config of Generic Colouriser for php and yii logs. http://kassiopeia.juls.savba.sk/~garabik/software/grc.html
regexp=\] PHP [^\s]+ error:
colours=red
count=block
---
regexp=\] PHP Notice:
colours=yellow
count=block
---
regexp=\] PHP Warning:
colours=cyan
@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.