Skip to content

Instantly share code, notes, and snippets.

View kkamkou's full-sized avatar

Konstantin Kamkou kkamkou

View GitHub Profile
@kkamkou
kkamkou / osrm-thread-watchdog-server.sh
Last active June 4, 2019 09:40
Primitive bash http server to serve the status
#!/usr/bin/env bash
# Example:
# script.sh /tmp/status [8080] [40]
while true; do
PERCENT=`(cat ${1} | grep "Load:" | cut -d" " -f2) 2>/dev/null`
STATUS=`[[ -z "${PERCENT}" || "${PERCENT}" -gt ${3-79} ]] && echo "503" || echo "204"`
echo -e "HTTP/1.1 ${STATUS} OK\r\n\r\n" | nc -l --send-only -p ${2-8080} 1>/dev/null
done
@kkamkou
kkamkou / osrm-thread-watchdog.sh
Created June 4, 2019 08:28
Observes OSRM instance for busy threads
#!/usr/bin/env bash
# Observes OSRM instance for busy threads.
# Remark: an instance must have any activity, otherwise the script will assume
# all forks are long-running.
#
# Arguments:
# $1 - timeout to consider a fork as "dirty" (in seconds)
#
# Example:
@kkamkou
kkamkou / Java SE 8 Programmer I.md
Last active March 26, 2017 10:20
Exam topics and links for Java 8 and MySQL 5.6
@kkamkou
kkamkou / env-setup.sh
Last active February 20, 2017 09:38
Shell customization on a remote server
#!/bin/sh
#@author Kanstantsin Kamkou <kkamkou@gmail.com>
if [ "`id -u`" = "0" ]; then
echo "Do not run this script as root" 1>&2
exit 1
fi
LIST_PIP='pip pip-tools httpie docker-compose'
@kkamkou
kkamkou / node-microdata.js
Created October 24, 2013 12:34
Gets micro-data from html
// required stuff
var _ = require('lodash'),
cheerio = require('cheerio');
// exporting outside
module.exports = {
/**
* Converts a html code to the object
* @param {String} html
* @returns {Object}
@kkamkou
kkamkou / dejavu.js
Last active September 13, 2019 12:14
express.js caching (middleware)
/**
* @category Application
* @package Middleware
* @author Kanstantsin A Kamkou (kkamkou@gmail.com)
*/
// tiny caching engine
var Dejavu = function () {
// default cache holder
this._cache = [];
@kkamkou
kkamkou / router.js
Last active December 10, 2015 00:08
express.js custom router (middleware)
/**
* @category Application
* @package Middleware
* @author Kanstantsin A Kamkou (kkamkou@gmail.com)
*/
// required
var fs = require('fs'),
express = require('express'),
path = require('path');
@kkamkou
kkamkou / url.js
Last active October 13, 2015 04:28
express.js route to url with options replacement
/**
* @category Library
* @package Utilits
* @author Kanstantsin A Kamkou (kkamkou@gmail.com)
*/
var _ = require('lodash');
/**
* Converts route to the url, replacing keys if needed
@kkamkou
kkamkou / .htaccess
Created September 20, 2012 11:00
mod_rewrite caching rules
#author Kanstantsin A Kamkou (2ka.by)
<IfModule mod_setenvif.c>
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch SV1; !no_gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
</IfModule>
<IfModule mod_deflate.c>
@kkamkou
kkamkou / jquery.urn.js
Created September 10, 2012 17:50
Input normalization for the URN field
/**
* @author Kanstantsin A Kamkou (2ka.by)
*
* Example:
* $('#myField').urn();
* $('#myField').urn({on: 'keyup'});
*/
(function ($) {
"use strict";