Skip to content

Instantly share code, notes, and snippets.

View nmmmnu's full-sized avatar

Nikolay Mihaylov nmmmnu

View GitHub Profile
<?
require_once "php_cache.php";
echo 123456;
phpinfo();
@nmmmnu
nmmmnu / create.sql
Created July 19, 2011 22:32
Indexing library for PHP/MySQL
CREATE TABLE `data_index` (
`id` int(11) NOT NULL,
`num` smallint(6) NOT NULL,
`word` varchar(33) DEFAULT NULL,
PRIMARY KEY (`id`,`num`),
KEY `word` (`word`,`id`),
KEY `id` (`id`,`word`)
);
@nmmmnu
nmmmnu / redis_search_test.php
Created August 5, 2011 09:28
Get PHP associative array from Redis search result
$r = new Redis();
$r->connect($redis_ip, $redis_port);
$data = $r->sort("all:srv", array(
"get" => array("srv:*->port", "srv:*->mem" )
)
);
print_r(redis_transpose_sort($data, array("port", "mem") ) );
@nmmmnu
nmmmnu / memcached2redis.php
Created August 12, 2011 18:46
Memcached 2 Redis wrapper
<?
/*
=========================
Memcached 2 Redis wrapper
=========================
Version 1.0.1, CopyLeft 2011.AUG.11
@nmmmnu
nmmmnu / select_echo_server.php
Created November 30, 2011 08:32
PHP based select() server
<?
/*
This is server written in PHP that employ socket select() method.
It is single threaded and does not fork, but rather process the clients "very" fast one by one.
Redis, nginx and Lighttpd works in similar way.
This source was found on the net, but I did lots of changes in order to get it work.
To make things simple, server is changed to be echo server, it simply print back what you send.
After starting the file, you should do:
@nmmmnu
nmmmnu / bozo.php
Created March 28, 2012 20:45
Bozo Sort
<?
/*
Bozo Sort written in PHP
Nikolay Mihaylov Copyleft 2012-03-28, Sofia
*/
function is_sorted($a){
for($i=0; $i < count($a) - 1; $i++)
if ($a[$i] > $a[$i + 1])
return false;
@nmmmnu
nmmmnu / shell.php
Created March 28, 2012 20:46
Improved Shell Sort
<?
function shell_sort($a){
$step = count($a) - 1;
while ( true ){
$sorted = false;
echo sprintf("Step %3d\n", $step);
@nmmmnu
nmmmnu / gist:2709432
Created May 16, 2012 10:42
Cassandra Iterator test on very long data set
<?
require_once(__DIR__.'/../lib/autoload.php');
use phpcassa\SystemManager;
use phpcassa\Connection\ConnectionPool;
use phpcassa\ColumnFamily;
use phpcassa\Index\IndexExpression;
use phpcassa\Index\IndexClause;
@nmmmnu
nmmmnu / cqlsh.php
Created May 17, 2012 22:09
Cassandra cqlsh replacement written in php
!/usr/local/bin/php
<?
require_once(__DIR__.'/../lib/autoload.php');
use phpcassa\Connection\ConnectionPool;
if ($argc < 2){
echo "Usage {$argv[0]} keyspace cql\n";
exit;
@nmmmnu
nmmmnu / gist:2757963
Created May 20, 2012 12:34
cassandra probl reproduction
server1:
[default@DEMO] set x[abc][1] = 5;
Value inserted.
Elapsed time: 1 msec(s).
server2:
[default@DEMO] set x[abc][2] = 6;
Value inserted.