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 / download_file_save_as.js
Last active February 18, 2019 21:52
JavaScript Download (Save AS)
// https://stackoverflow.com/questions/23451726/saving-binary-data-as-file-using-javascript-from-a-browser
var sampleBytes = new Int8Array(4096);
var saveByteArray = (function () {
var a = document.createElement("a");
document.body.appendChild(a);
a.style = "display: none";
return function (data, name) {
var blob = new Blob(data, {type: "octet/stream"}),
url = window.URL.createObjectURL(blob);
a.href = url;
#!/bin/bash
#Thanks to https://wiki.zoneminder.com/Raspbian
if [ "$(whoami)" != "root" ]; then
echo "Run script as ROOT please. (sudo !!!)"
exit
fi
# Disable Wi-Fi and Bluetooth
@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"});
#!/bin/bash
#https://ayesh.me/Ubuntu-PHP-7.2
#http://linux-notes.org/ustanovka-mysql-na-debian-ubuntu-linux-mint/
#https://www.digitalocean.com/community/tutorials/apache-ubuntu-14-04-lts-ru
#https://stackoverflow.com/questions/3940909/configure-apache-to-listen-on-port-other-than-80
#https://www.tecmint.com/change-default-mysql-mariadb-port-in-linux/
sudo apt-get update
sudo apt-get upgrade
#!/bin/bash
# https://github.com/Open365/Open365
# https://superuser.com/questions/769920/python3-pip-installed-but-pip3-command-not-found
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install -y git vim mc
sudo apt-get install -y python3
@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;