Skip to content

Instantly share code, notes, and snippets.

Avatar

Kanstantsin Kamkou kkamkou

View GitHub Profile
@kkamkou
kkamkou / osrm-thread-watchdog-server.sh
Last active Jun 4, 2019
Primitive bash http server to serve the status
View osrm-thread-watchdog-server.sh
#!/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 Jun 4, 2019
Observes OSRM instance for busy threads
View osrm-thread-watchdog.sh
#!/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 Mar 26, 2017
Exam topics and links for Java 8 and MySQL 5.6
View Java SE 8 Programmer I.md
@kkamkou
kkamkou / env-setup.sh
Last active Feb 20, 2017
Shell customization on a remote server
View env-setup.sh
#!/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 Oct 24, 2013
Gets micro-data from html
View node-microdata.js
// 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 Sep 13, 2019
express.js caching (middleware)
View dejavu.js
/**
* @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 Dec 10, 2015
express.js custom router (middleware)
View router.js
/**
* @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 Oct 13, 2015
express.js route to url with options replacement
View url.js
/**
* @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 Sep 20, 2012
mod_rewrite caching rules
View .htaccess
#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 Sep 10, 2012
Input normalization for the URN field
View jquery.urn.js
/**
* @author Kanstantsin A Kamkou (2ka.by)
*
* Example:
* $('#myField').urn();
* $('#myField').urn({on: 'keyup'});
*/
(function ($) {
"use strict";