Skip to content

Instantly share code, notes, and snippets.

@romfrolov
romfrolov / check-internet.js
Created April 10, 2019 19:02
Check internet connection in Nodejs.
'use strict';
const dns = require('dns').promises;
/**
* Check connection to internet.
*
* @return {Promise<Boolean>} Whether there is connection to internet or not.
*/
exports.checkInternet = function checkInternet() {
@romfrolov
romfrolov / psql-backup.sh
Last active April 13, 2019 07:38
Postgres backup.
# backup your databases
docker exec -t your-db-container pg_dumpall -c -U postgres > dump_`date +%d-%m-%Y"_"%H_%M_%S`.sql
# restore your databases
cat your_dump.sql | docker exec -i your-db-container psql -U postgres
@romfrolov
romfrolov / docker-compose.yml
Last active June 9, 2019 07:14
Minimalistic Let's Encrypt docker-compose configuration using linuxserver/letsencrypt image.
version: '3'
services:
letsencrypt:
image: linuxserver/letsencrypt
container_name: letsencrypt
restart: unless-stopped
network_mode: host
volumes:
- ./config/letsencrypt:/config
@romfrolov
romfrolov / bubble.rs
Last active November 9, 2019 22:56
Bubble sort in Rust.
fn bubble_sort(mut array: Vec<isize>) -> Vec<isize> {
let mut swapped: bool;
loop {
swapped = false;
for i in 0..array.len() - 1 {
if array[i] > array[i + 1] {
let temp = array[i];
array[i] = array[i + 1];
@romfrolov
romfrolov / delete-merged-branches.sh
Last active April 30, 2021 23:21
Delete all merged branches
# Delete all local branches that have been merged.
function delete_merged_branches() {
git branch --merged | egrep -v "(^\*|master)" | xargs git branch -d
}