Skip to content

Instantly share code, notes, and snippets.

@luchaninov
luchaninov / mongodb-status.sh
Last active August 29, 2015 14:03
Check if Mongo is working
#!/bin/bash
TEST="TEST PASSED"
RESULT="`mongo --quiet --eval \"print('${TEST}');\" 2> /dev/null | grep --color=never \"${TEST}\"`"
if [[ "${RESULT}" == "${TEST}" ]]; then
echo "Mongo is working"
else
echo "Mongo is not working"
fi
@luchaninov
luchaninov / php_encode
Last active August 29, 2015 14:06
pretty var_export
<?php
function php_encode($data)
{
if (is_string($data)) {
return '\'' . $data . '\'';
}
if (!is_array($data) && !is_object($data)) {
return $data;
}
@luchaninov
luchaninov / symfony-console
Created September 4, 2014 12:59
Bash autocomplete for symfony/console
#!/bin/bash
#
# bash completion support for symfony2 console
#
# INSTALL:
# save to /etc/bash_completion.d/symfony-console
#
# Copyright (C) 2011 Matthieu Bontemps <matthieu@knplabs.com>
# Distributed under the GNU General Public License, version 2.0.
@luchaninov
luchaninov / readme.md
Last active August 29, 2015 14:20
Задание

Суть задания

Необходимо обработать файл searches.csv и показать результат в формате:

Word,Count,Total Broad Searches,Total Exact Searches
киев,30,28374,10040
окна,17,3827,1373
...
5948 https://github.com/eryx/php-framework-benchmark
1324 https://github.com/symfony/symfony
988 https://github.com/xpressengine/xe-core
780 https://github.com/LExpress/symfony1
622 https://github.com/dupondje/PHP-Push-2
615 https://github.com/nfephp-org/nfephp
481 https://github.com/phpbb/phpbb
479 https://github.com/michael-romer/zf-boilerplate
472 https://github.com/phpmyadmin/phpmyadmin
464 https://github.com/yiisoft/yii
86937 isset
43159 echo
31697 empty
29252 substr
26146 count
24248 is_array
22572 strlen
19365 sprintf
18090 unset
16584 str_replace
@luchaninov
luchaninov / levenshtein.js
Last active August 28, 2020 20:36
Levenshtein distance is a string metric for measuring the difference between two sequences. Informally, the Levenshtein distance between two words is the minimum number of single-character edits (i.e. insertions, deletions or substitutions) required to change one word into the other.
// from https://github.com/thinkphp/String.levenshtein/blob/master/Source/String.levenshtein.js but no depencencies
function levenshtein(str1, str2) {
var cost = new Array(),
n = str1.length,
m = str2.length,
i, j;
var minimum = function(a, b, c) {
var min = a;
if (b < min) {
@luchaninov
luchaninov / rest-bookmarks.md
Last active July 12, 2017 13:21
REST Bookmarks

REST Bookmarks

Сервис закладок позволяет добавлять URL и оставлять к ним комментарии.

Сущности

Это не таблицы в базе данных, а то, что должен получать клиент API. Как хранить - решите сами.

if ($http_user_agent ~* "Java\/|^1C$|SemrushBot|Sitemap|intelium_bot|sqlmap|SiteTruth|openwebspider|Microsoft\sURL|URLChecker|Abonti|integromedb|CommentReader|findlinks|icjobs|PagesInventory|Wotbox|spray-can|spbot|Add\sCatalog|LinksCrawler|ePochta|LSSRocketCrawler|Sogou|SEOENGBot|searchmetrics|BlogPulseLive|gooblog|start.exe|YesupBot|Snoopy|BDP\sReferral|SmartCJ|GSLFbot|Jigsaw|AcoonBot|Influencebot|Lipperhey|coccoc|CCBot|fastbot|cctld.ru|Plesk|Sparrow|swebot|Gigabot|JoeDog|EC2LinkFinder|Exabot|GoScraper|SeznamBot|discobot|cmscrawler|Asynchronous\sWinHTTP|Purebot|netEstate|Referrer\sKarma|^Mozilla\/4\.0$|sistrix|AhrefsBot|Lunasys|SearchBot|Aboundex|RTS\/|yacybot|MLBot|nerdbynature|Parking\sDomains|OffByOne|Sosospider|WebIndex|ZumBot|Ezooms|SiteIntel|Zend_Http_Client|rganalytics|Synapse|pirst|FreeWebMonitoring|MJ12bot|ABBYY|Morfeus|dragostea|multi_get|^oBot$|C-T\sbot|python|nikto|wkito|pikto|scan|acunetix|HTTrack|clshttp|harvest|loadimpact|Mozilla\s\/\s4\.0|nutch|Gootkit|DomainCrawler|curl|ZmEu|Solomono|DomainW

Keybase proof

I hereby claim:

  • I am luchaninov on github.
  • I am luchaninov (https://keybase.io/luchaninov) on keybase.
  • I have a public key whose fingerprint is 0B3B 9EF3 53F3 2468 A1E7 0437 8A5D EEC4 7F69 54A4

To claim this, I am signing this object: