Skip to content

Instantly share code, notes, and snippets.

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

sokil

🇺🇦
sapere aude
View GitHub Profile
@sokil
sokil / decorator.php
Created August 27, 2014 08:04
PHP Decorator pattern
<?php
abstract class AbstractWindow
{
protected $_title;
public function __construct($title = null)
{
$this->_title = $title;
}
@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 / array_rand_weight.php
Last active July 20, 2016 04:40
Get random key from array due to weight in value.
<?php
function array_rand_weight(array $array)
{
reset($array);
$pointer = mt_rand(0, array_sum($array));
if(!$pointer) {
return key($array);
}
@sokil
sokil / consolecolor.php
Last active November 14, 2019 09:05
Console color
<?php
// new lines
// echo "\033[{$line};{$column}H";
// \r - goto start of line
$foregroundColors = array(
'white' => '1;37',
'black' => '0;30',
'dark_gray' => '1;30',
@sokil
sokil / pointer.c
Last active August 9, 2019 06:48
C++ pointers and dereferencing
/**
* Compile and execute:
* g++ pointer.c -o pointer && ./pointer
*/
#include <iostream>
#include <typeinfo>
using namespace std;
@sokil
sokil / Hashtable.sh
Last active April 3, 2018 07:39
Shell hashtable
CCList=(
"GBR:GB"
"USA:US"
"CAN:CA"
"NLD:NL"
"NZL:NZ"
"ZAF:ZA"
"IRL:IE"
"CZE:CZ"
"AUS:AU"
@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();
@sokil
sokil / cookie.js
Created January 30, 2015 07:01
Cookie inJavaScript