Skip to content

Instantly share code, notes, and snippets.

View akostylev0's full-sized avatar

Andrei Kostylev akostylev0

View GitHub Profile
did
am
ones
me
@akostylev0
akostylev0 / php-shim.sh
Created November 22, 2016 16:26
php shim for phpstorm
#!/usr/bin/env bash
cd `dirname $0`
DIR="/your/work/dir"
exec docker run --env XDEBUG_CONFIG="$XDEBUG_CONFIG" -w="$DIR" --net="host" --rm -v /tmp:/tmp -v "$DIR":"$DIR" \
your-php-image-name php "$@"
<?php
function map($collection) : \Generator
{
if (is_array($collection) || $collection instanceof \Traversable)
{
foreach($collection as $element) {
yield $element;
}
}
throw new \InvalidArgumentException();
@akostylev0
akostylev0 / Liberal Regex Pattern for Web URLs
Last active August 29, 2015 14:27 — forked from gruber/Liberal Regex Pattern for Web URLs
Liberal, Accurate Regex Pattern for Matching Web URLs
The regex patterns in this gist are intended only to match web URLs -- http,
https, and naked domains like "example.com". For a pattern that attempts to
match all URLs, regardless of protocol, see: https://gist.github.com/gruber/249502
# Single-line version:
(?i)\b((?:https?:(?:/{1,3}|[a-z0-9%])|[a-z0-9.\-]+[.](?:com|net|org|edu|gov|mil|aero|asia|biz|cat|coop|info|int|jobs|mobi|museum|name|post|pro|tel|travel|xxx|ac|ad|ae|af|ag|ai|al|am|an|ao|aq|ar|as|at|au|aw|ax|az|ba|bb|bd|be|bf|bg|bh|bi|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|cr|cs|cu|cv|cx|cy|cz|dd|de|dj|dk|dm|do|dz|ec|ee|eg|eh|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gg|gh|gi|gl|gm|gn|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|im|in|io|iq|ir|is|it|je|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|me|mg|mh|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|mv|mw|mx|my|mz|na|nc|ne|nf|ng|ni|nl|no|np|nr|nu|nz|om|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|ps|pt|pw|py|qa|re|ro|rs|ru|rw|sa|sb|sc|sd|se|sg|sh|si|s
# coding=utf-8
from collections import defaultdict
import random
import time
class AhoCorasick(object):
class Node(object):
def __init__(self):
self.next = defaultdict(AhoCorasick.Node)
@akostylev0
akostylev0 / gist:c180456931ac9d062d4e
Created October 13, 2014 14:37
nf_conntrack: table full, dropping packet
net.ipv4.netfilter.ip_conntrack_max=1548576
Defaults env_keep+=SSH_AUTH_SOCK
--partitioning like http://www.postgresql.org/docs/9.3/static/ddl-partitioning.html
--create master table
CREATE TABLE master_table
(
id serial,
key character varying NOT NULL,
value character varying NOT NULL,
CONSTRAINT master_table_pkey PRIMARY KEY (id)
);
--create slave tables with constraint
@akostylev0
akostylev0 / tornading
Created May 14, 2012 11:16
service tornading
#!/bin/bash
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/bin/python
ARGS="/home/manage/web/$2/deploy/tornading.py"
PID_PATH=/home/manage/web/$2/deploy/$2.pid
NAME=tornading
DESC=tornading
APPS=`ls /home/manage/web/`
if [ $# -eq "2" ]; then