Simple and safe random getters to copy-paste
string randomBytes( int $length )
int randomInt ( int $min , int $max )
string randomUuid ( void )
<?php | |
/** @var CController $controller */ | |
$controller->widget( | |
'zii.widgets.grid.CGridView', | |
array( | |
'columns' => array( | |
array( | |
'header' => 'Row', | |
'value' => '$row + ($this->grid->dataProvider->pagination->currentPage |
# this vhost config sends my custom 404 page on not-found errors. but the `return 503` causes nginx | |
# to send its own built-in error page. why is that? how to change this config so it sends my 503.html? | |
server { | |
listen 80; | |
server_name tarfu.example.com; | |
root /var/www/v2/doc_root/web; | |
if ($maintenance = 1) { | |
return 503; | |
} |
<?php | |
/** | |
* Inspect your globals. | |
* | |
* Include this file to display any globals that might be defined. Maybe exit() afterwards. | |
* | |
* @author Tom Worster <fsb@thefsb.org> | |
* @link https://gist.github.com/tom--/5876699 | |
* @copyright Copyright © 2013 Tom Worster | |
* @license BSD 2-clause http://opensource.org/licenses/BSD-2-Clause |
I have an interesting Yii 2 AR design problem.
The DB has 12 primary entity tables related via a full mesh of 72 join tables. Each relation also has a type (and attributes) but those aren't stored in the join tables – they are in additional tables that the 72 join tables reference. So each of the 72 join tables provides a 3-way join between one entity, another entity and another table called link that points to the link_type.
My problem is to write the AR models and relation methods.
Let's make this more concrete with two of the primary entities: artist and recording, related through l_artist_recording. Each record of l_artist_recording has an FK to the link table, through which I can load the link_type name. For example, an artist-recording relation might have link_type "performer", "conductor", or "producer" etc.
This is a simplified schma good enough for thinking about the AR p
Hexdump traffic over interface I to and from TCP server on port P of host H
tcpdump -p -i I -lttttX 'tcp and ((dst port P and dst host H) or (src port P and src host H))'
in which
I
is interface nameP
is port numberH
is host name or addressMariaDB [(none)]> create schema test collate utf8_general_ci; | |
Query OK, 1 row affected (0.000 sec) | |
MariaDB [(none)]> set names utf8; | |
Query OK, 0 rows affected (0.000 sec) | |
MariaDB [(none)]> use test | |
Database changed | |
MariaDB [test]> create table test (id int not null primary key, name varchar(99) not null); | |
Query OK, 0 rows affected (0.002 sec) |
#!/usr/local/bin/php | |
<?php | |
$error = false; | |
$errno = 0; | |
try { | |
$db = new PDO('mysql:dbname=stations;host=localhost', 'root', 'password'); | |
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); | |
/** @var $slave_status StdClass */ |
The playlist needs a title, start and end times, and an owner. Spinitron looks at the schedule: Is there a show in today's calendar spanning 10:01? Zero, one or more shows can satisfy this query.
If zero, Spinitron creates a generic playlist without using a show as template and the playlist is owned by the "automation persona". If more than one, having no better criteria, Spinitron chooses the most recently created show. If only one, there is no fuss.
Assuming a show was found, Spinitron copies over the title, start and end times and DJ. But a playlist can have only one DJ and a show can have one or more. If more than one, having no better criteria, Spinitron chooses the most recently created DJ. If only one, there is no fuss.