Skip to content

Instantly share code, notes, and snippets.

<?php
//https://en.wikipedia.org/wiki/Median
function calcAvg($arr)
{
$avg = (array_sum($arr)/count($arr));
return $avg;
}
function calcMedian($arr)
@bspavel
bspavel / xvfb
Created February 17, 2017 17:37 — forked from jterrace/xvfb
xvfb init script for Ubuntu
XVFB=/usr/bin/Xvfb
XVFBARGS=":1 -screen 0 1024x768x24 -ac +extension GLX +render -noreset"
PIDFILE=/var/run/xvfb.pid
case "$1" in
start)
echo -n "Starting virtual X frame buffer: Xvfb"
start-stop-daemon --start --quiet --pidfile $PIDFILE --make-pidfile --background --exec $XVFB -- $XVFBARGS
echo "."
;;
stop)
@bspavel
bspavel / bytesToSize.js
Created December 12, 2017 12:11 — forked from lanqy/bytesToSize.js
JavaScript To Convert Bytes To MB, KB, Etc
// from http://scratch99.com/web-development/javascript/convert-bytes-to-mb-kb/
function bytesToSize(bytes) {
var sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB'];
if (bytes == 0) return 'n/a';
var i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024)));
if (i == 0) return bytes + ' ' + sizes[i];
return (bytes / Math.pow(1024, i)).toFixed(1) + ' ' + sizes[i];
};
@bspavel
bspavel / install.bash
Created January 4, 2018 15:42 — forked from isc30/install.bash
Raspberry Pi Install PHP7 + Nginx + MySQL + PhpMyAdmin (last versions)
#!/bin/bash
# Thanks to https://gist.github.com/Lewiscowles1986/ce14296e3f5222082dbaa088ca1954f7
if [ "$(whoami)" != "root" ]; then
echo "Run script as ROOT please. (sudo !!)"
exit
fi
echo "deb http://mirrordirector.raspbian.org/raspbian/ stretch main contrib non-free rpi" > /etc/apt/sources.list.d/stretch.list
echo "APT::Default-Release \"jessie\";" > /etc/apt/apt.conf.d/99-default-release
@bspavel
bspavel / IndexedDB101.js
Created February 17, 2018 12:54 — forked from JamesMessinger/IndexedDB101.js
Very Simple IndexedDB Example
// This works on all devices/browsers, and uses IndexedDBShim as a final fallback
var indexedDB = window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB || window.shimIndexedDB;
// Open (or create) the database
var open = indexedDB.open("MyDatabase", 1);
// Create the schema
open.onupgradeneeded = function() {
var db = open.result;
var store = db.createObjectStore("MyObjectStore", {keyPath: "id"});
@bspavel
bspavel / notes-IndexedDB.html
Created May 2, 2018 09:11 — forked from greenido/notes-IndexedDB.html
Simple indexedDB example that will work both in Chrome and FF
<!DOCTYPE html>
<head>
<script>
var db;
// until we won't need this prefix mess
var indexedDB = window.indexedDB || window.webkitIndexedDB
|| window.mozIndexedDB || window.msIndexedDB;
var IDBTransaction = window.IDBTransaction ||
window.webkitIDBTransaction;
@bspavel
bspavel / download-and-install.sh
Created July 8, 2018 10:55 — forked from andrius/download-and-install.sh
Script to download and install Asterisk PBX, Ruby and Adhearsion AGI on debian-based system
#!/bin/bash
# function to generate random password, on input requires an argument - lenght of password
genpasswd() {
local l=$1
[ "$l" == "" ] && l=20
tr -dc A-Za-z0-9_ < /dev/urandom | head -c ${l} | xargs
}
# MySQL default root password
@bspavel
bspavel / query-string-example.js
Created July 12, 2018 08:11 — forked from sindresorhus/query-string-example.js
Get, set, modify url parameters in a query string with JavaScript.
// Get the queryString module from:
// https://github.com/sindresorhus/query-string
console.log(location.href);
// http://sindresorhus.com/?foo=bar
console.log(location.search);
// ?foo=bar
var parsed = queryString.parse(location.search);
@bspavel
bspavel / jenkins.conf
Created August 16, 2018 10:55 — forked from razbakov/jenkins.conf
Jenkins Apache Virtual Host
<Virtualhost *:80>
ServerName your.url.com
ProxyRequests Off
ProxyPreserveHost On
AllowEncodedSlashes NoDecode
<Proxy http://localhost:8080/*>
Order deny,allow
Allow from all
</Proxy>
@bspavel
bspavel / guacamole install on ubuntu 16.04
Created August 18, 2018 18:48 — forked from cyrex562/guacamole install on ubuntu 16.04
guacamole install on ubuntu 16.04
# install required packages
add-apt-repository ppa:webupd8team/java
apt -y update
apt -y upgrade
apt -y dist-upgrade
apt -y install libcairo2-dev libjpeg-turbo8-dev libpng12-dev libossp-uuid-dev libfreerdp-dev libpango1.0-dev libssh2-1-dev libtelnet-dev \
libvncserver-dev libpulse-dev libssl-dev libvorbis-dev libwebp-dev git build-essential autoconf libtool oracle-java8-installer tomcat8 \
tomcat8-admin tomcat8-common tomcat8-docs tomcat8-user maven mysql-server mysql-client mysql-common mysql-utilities libpulse-dev \
libvorbis-dev freerdp ghostscript wget