Skip to content

Instantly share code, notes, and snippets.

View sokil's full-sized avatar
🇺🇦
sapere aude

sokil

🇺🇦
sapere aude
View GitHub Profile
<?php
$request = $guzzleClient->get('/');
$request->addSubscriber(new \Guzzle\Plugin\Mock\MockPlugin(array(
new \Guzzle\Http\Message\Response(200, null, json_encode(array(
'error' => 0,
)))
)));
$response = $request->send();
@sokil
sokil / newsyslog.conf
Created May 19, 2014 11:53
Log rotation for nginx+php-fpm stack on FreeBSD
# log rotation for nginx+php-fpm stack on FreeBSD
# File: /etc/newsyslog.conf
/var/log/nginx/*.log 644 15 1000 @T00 JBCG /var/run/nginx.pid 30
/var/log/php_errors.log www:www 644 15 1000 @T00 JBCG /var/run/php-fpm.pid 30
<?php
/**
* @link http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.3.1
*/
function timestampToHttpDate($timestamp) {
return gmdate('D, d M Y H:i:s', $timestamp) . ' GMT';
}
@sokil
sokil / redis.queue.consumer.php
Last active August 29, 2015 14:05
Redis queue
<?php
$client = new \Predis\Client([
'read_write_timeout' => 0,
]);
while(true) {
$message = $client->blpop('queue1', 0);
}
<?php
use PhpAmqpLib\Connection\AMQPConnection;
use PhpAmqpLib\Message\AMQPMessage;
// connect
$connection = new AMQPConnection('localhost', 5672, 'guest', 'guest');
// create channel
$channel = $connection->channel();
<?php
use PhpAmqpLib\Connection\AMQPConnection;
use PhpAmqpLib\Message\AMQPMessage;
// connect
$connection = new AMQPConnection('localhost', 5672, 'guest', 'guest');
// create channel
$channel = $connection->channel();
@sokil
sokil / YiiPsrLogAdapter.php
Last active August 29, 2015 14:05
Yii-PSR Log Adapter
<?php
use Psr\Log\LogLevel;
class PsrLogAdapter extends \Psr\Log\AbstractLogger
{
private $_levelMap = array(
LogLevel::EMERGENCY => CLogger::LEVEL_ERROR,
LogLevel::ALERT => CLogger::LEVEL_ERROR,
LogLevel::CRITICAL => CLogger::LEVEL_ERROR,
@sokil
sokil / schema.xml
Last active August 29, 2015 14:05
Apache Solr
<?xml version="1.0" encoding="UTF-8" ?>
<schema name="symfony" version="1.0">
<uniqueKey>id</uniqueKey>
<fieldType name="long" class="solr.TrieLongField" precisionStep="0" positionIncrementGap="0"/>
<fieldType name="string" class="solr.StrField" sortMissingLast="true" />
<field name="_version_" type="long" indexed="true" stored="true"/>
<field name="_root_" type="string" indexed="true" stored="false"/>
<field name="id" type="string" indexed="true" stored="true" required="true" multiValued="false" />
<?php
function dropDirectory($path) {
// drop included files and directories
foreach(new \DirectoryIterator($path) as $file) {
if($file->isDot()) {
continue;
}
// drop dir
@sokil
sokil / server.js
Created December 31, 2014 18:11
Node.js server
var http = require('http');
// create server
var server = http.createServer();
// dispatch requests
server.on('request', function(request, response) {
response.writeHead(200, 'OK');
response.write('Requested ' + request.url);
response.end();