Skip to content

Instantly share code, notes, and snippets.

View samdark's full-sized avatar
🛠️
Improving everything

Alexander Makarov samdark

🛠️
Improving everything
View GitHub Profile
<?php
$start = microtime(true);
function get_cache_value() {
return rand(0, 100).'test';
}
$results = array();
for ($i=0; $i<1000; $i++) {
$results[] = get_cache_value();
@samdark
samdark / ClearAssetsCommand.php
Created April 5, 2013 10:14
Yii command to clear assets
<?php
/**
* Clear assets Command
*
* Deletes all published assets.
*
* Usage:
* yiic clearassets
*
* @author Alexander Makarov
@samdark
samdark / devmeeting.md
Last active December 11, 2015 17:28
Встреча разработчиков, Воронеж #1
@samdark
samdark / php_variable_name_memory_usage.php
Created January 21, 2013 09:17
Memory usage of long and short variable names
<?php
class X
{
private $_b;
private $_e;
}
class Y
{
private $_behaviors;
@samdark
samdark / taggable_or.php
Created October 3, 2012 09:36
Find by any of tags for taggable Yii extension
/**
* Get criteria to limit query to match any of tags specified
* @access private
* @param array $tags
* @return CDbCriteria
*/
protected function getFindByAnyTagsCriteria($tags) {
$criteria = new CDbCriteria();
$pk = $this->getOwner()->tableSchema->primaryKey;
@samdark
samdark / github-post-receive.php
Last active October 11, 2019 10:05
Simple GitHub post-receive PHP hook
<?php
function cidr_match($ip, $ranges)
{
$ranges = (array)$ranges;
foreach($ranges as $range) {
list($subnet, $mask) = explode('/', $range);
if((ip2long($ip) & ~((1 << (32 - $mask)) - 1)) == ip2long($subnet)) {
return true;
}
}
@samdark
samdark / render_leveled_list_as_ul.php
Created June 29, 2012 08:31
Render leveled list as unordered list
<?php
function render_level_list($items)
{
$level=0;
foreach($items as $item)
{
if($item->level==$level) {
echo "</li>\n";
}
@samdark
samdark / yii_functions_sql.php
Created June 21, 2012 19:33
Yii: handy functions to use Yii with raw SQL
<?php
/**
* Escapes values
*
* @param array $values array of values to escape
* @return string string ready to be included into SQL statement
* @throws CException if one of the values isn't a scalar
*/
function escape($values)
{
@samdark
samdark / Object.php
Created May 30, 2012 12:22
Yii2, Object
<?php
/**
* Object class file.
*
* @link http://www.yiiframework.com/
* @copyright Copyright &copy; 2008-2012 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace yii\base;
@samdark
samdark / Component.php
Created May 30, 2012 12:21
Yii2, Component
<?php
/**
* Component class file.
*
* @link http://www.yiiframework.com/
* @copyright Copyright &copy; 2008-2012 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace yii\base;