Skip to content

Instantly share code, notes, and snippets.

View DmitryMyadzelets's full-sized avatar

Dmitry Myadzelets DmitryMyadzelets

View GitHub Profile
@DmitryMyadzelets
DmitryMyadzelets / index.js
Last active September 23, 2017 23:15
Combination
const factorial = (n) => n ? n * factorial(n - 1) : 1
// Given n, choose k - [Combination](https://en.wikipedia.org/wiki/Combination)
const C = (n, k) => factorial(n) / (factorial(k) * factorial(n-k))
@DmitryMyadzelets
DmitryMyadzelets / speedtests.md
Last active February 15, 2018 19:02
Networking
curl -s https://raw.githubusercontent.com/sivel/speedtest-cli/master/speedtest.py | python -

Example output:

Retrieving speedtest.net configuration...
Testing from WIND (151.48.54.99)...
Retrieving speedtest.net server list...
Selecting best server based on ping...
@DmitryMyadzelets
DmitryMyadzelets / raspi-monitor
Created June 28, 2017 12:18 — forked from simlun/raspi-monitor
Script to enable and disable the HDMI signal of the Raspberry PI
#!/bin/bash -e
# /usr/local/sbin/raspi-monitor
# Script to enable and disable the HDMI signal of the Raspberry PI
# Inspiration: http://www.raspberrypi.org/forums/viewtopic.php?t=16472&p=176258
CMD="$1"
function on {
/opt/vc/bin/tvservice --preferred
@DmitryMyadzelets
DmitryMyadzelets / ready.js
Created May 30, 2017 14:19
When a web page is ready for manipulation. Altrernative for jQuery ready()
// Invokes callback when DOM is ready for manipulation
// Usage: ready(function () {});
function ready(callback) {
// Motivation:
// https://gomakethings.com/a-native-javascript-equivalent-of-jquerys-ready-method/
// Docs:
// https://developer.mozilla.org/en/docs/Web/API/Document/readyState
var loading, done;
{
"capricorn":"Capricorno",
"aquarius":"Acquario",
"pisces":"Pesci",
"aries":"Ariete",
"taurus":"Toro",
"gemini":"Gemelli",
"cancer":"Cancro",
"leo":"Leone",
"virgo":"Vergine",
@DmitryMyadzelets
DmitryMyadzelets / tidy_html.js
Created January 31, 2017 16:39
Tidy html gotten from div contenteditable='true'
function tidyHtml(html) {
return html
.replace(/( )+/gi, ' ') // Get back normal spaces
.replace(/\s+(<br>)/g, '\$1') // Remove spaces before <br>
.replace(/(<br>)\s+/g, '\$1') // Remove spaces after <br>
.replace(/\s{2,}/g, ' ') // Replace multiple spaces with one
.replace(/^(<br>)*/i, '') // Remove <br> at the beginning
.replace(/(<br>)*$/i, '') // ... and at the end
.replace(/(<br>){3,}/gi, '<br><br>'); // No more then two <br>
@DmitryMyadzelets
DmitryMyadzelets / readme.md
Last active February 3, 2023 19:21
SanDisc Clip Jam MP3 player file ordering for an audiobook

Remove all from the ID3 tag:

for f in *.mp3; do eyeD3 --remove-all "$f"; done

Given file names like name001.mp3, create new ID3 tag, and set the title to the index of the file:

for f in *.mp3; do i=`echo $f | grep -oP '\d\d\d'`; eyeD3 --to-v2.3 -t $i "$f"; done

The above scripts report the error: "No ID3 v1.x/v2.x tag found!". Ignore it.

@DmitryMyadzelets
DmitryMyadzelets / Telegram.md
Created January 10, 2017 14:44
Telegram Desktop on CrunchBang Debian Linux 7 Waldorf

Telegram Desktop on CrunchBang Debian Linux 7 Waldorf

(optional) Check your distro version

cat /etc/issue*

Output:

CrunchBang Linux waldorf \n \l
Debian GNU/Linux 7 \n \l
@DmitryMyadzelets
DmitryMyadzelets / @bash
Created December 17, 2016 17:41
Close calendar in Crunchbang
pkill gsimplecal