Skip to content

Instantly share code, notes, and snippets.

View miholeus's full-sized avatar
💭
🤖

miholeus

💭
🤖
View GitHub Profile
@miholeus
miholeus / Funny sequence
Created December 6, 2010 11:59
What is the next number 13211311123113112211 ?
<?php
$sequence[0] = '1';
//$sequence[1] = (count of numbers in $sequence[0]) //11
//$sequence[2] = (count of numbers in $sequence[1]) //21
function populate_sequence_row($sequence, $rowNumber)
{
if($rowNumber == 0) return 1;
$order = array();
@miholeus
miholeus / table_prefix.php
Created December 17, 2010 23:53
table prefix snippet in ZF
/* bootstrap file */
define('_TABLE_PREFIX', $config->db->table->prefix);
class Extend_Db_Table extends Zend_Db_Table_Abstract
{
/**
* This will automatically set table name with prefix from bootstrap file
* @return void
*/
protected function _setupTableName()
@miholeus
miholeus / table_prefix2.php
Created December 18, 2010 00:16
another version of setting prefix
class Mist_Db_Table extends Zend_Db_Table
{
public function __construct($config = array(), $definition = null)
{
parent::__construct($config, $definition);
$config = $this->getAdapter()->getConfig();
if(array_key_exists('prefix', $config))
{
@miholeus
miholeus / alphabetical_order_in_words.php
Created December 25, 2010 18:41
Find words in which letters are in alphabetical order
<?php
$str = "abcd 01234 87 01235 6 абвгд";
$words = preg_split("/\s/", $str, -1, PREG_SPLIT_NO_EMPTY);
function uniord($ch) {
$n = ord($ch{0});
if ($n < 128) {
return $n; // no conversion required
@miholeus
miholeus / jquery_zend.php
Created December 27, 2010 09:35
Initialize Jquery Helper In Bootstrap
<?php
protected function _initViewHelpers()
{
$view= new Zend_View();
$viewRenderer = new Zend_Controller_Action_Helper_ViewRenderer();
$view->addHelperPath('ZendX/JQuery/View/Helper/', 'ZendX_JQuery_View_Helper');
$viewRenderer->setView($view);
<?php
/**
* SplClassLoader implementation that implements the technical interoperability
* standards for PHP 5.3 namespaces and class names.
*
* http://groups.google.com/group/php-standards/web/final-proposal
*
* // Example which loads classes for the Doctrine Common package in the
* // Doctrine\Common namespace.
@miholeus
miholeus / PSR0 autoload
Created February 24, 2012 07:22
php namespace autoloader
public function autoload($className)
{
$className = ltrim($className, '\\');
$fileName = '';
$namespace = '';
if ($lastNsPos = strripos($className, '\\')) {
$namespace = substr($className, 0, $lastNsPos);
$className = substr($className, $lastNsPos + 1);
$fileName = str_replace('\\', DIRECTORY_SEPARATOR, $namespace) . DIRECTORY_SEPARATOR;
}
@miholeus
miholeus / remote_file.php
Created April 11, 2012 12:10
remote file download
if(!empty($remote)) {
$config = array(
'adapter' => 'Zend_Http_Client_Adapter_Curl',
'curloptions' => array(
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_HEADER => 0,
CURLOPT_CONNECTTIMEOUT => 5,
),
);
@miholeus
miholeus / type_hinting.php
Created April 13, 2012 19:46
PHP type hinting
set_error_handler('handle');
function foo(integer $p1, bool $p2) {
echo "ok" . PHP_EOL;
}
$param1 = 123;
$param2 = 'string val!';
foo($param1, $param2);
@miholeus
miholeus / application.yml
Created June 6, 2013 15:01
application.yml
base:
components:
db:
connectionString: 'mysql:host=localhost;dbname=default_crm'
username: o.mikhailov
password: ahPi7faiwei
connections:
developer:
connectionString: 'mysql:host=localhost;dbname=crm_extended'
username: o.mikhailov