Skip to content

Instantly share code, notes, and snippets.

@keepitsimple
keepitsimple / remove_old_snap.sh
Created August 13, 2023 11:42
Ubuntu remove old snap versions script
#!/bin/bash
# Removes old revisions of snaps
# CLOSE ALL SNAPS BEFORE RUNNING THIS
set -eu
snap list --all | awk '/disabled/{print $1, $3}' |
while read snapname revision; do
snap remove "$snapname" --revision="$revision"
done
@keepitsimple
keepitsimple / sh
Created August 13, 2023 11:40
Ubuntu 20.04 remove all shapshots in the bpool
zfs list -t snapshot -r | grep auto | cut -f1 -d' ' | xargs -n 1 sudo zfs destroy
@keepitsimple
keepitsimple / index.js
Created April 11, 2023 13:50
Пример буфера на получение данных и сохранением из него с debounce
/*
каждые 250 мс нам поступает асинхронно новая запись которая дописывается во входящий буфер
процедура записи извлекает элементы с начала буфера и записывает в лог файл.
процедура записи обернута в debounce
если данные не поступают 500 мс или более то происходит запись данных в лог файл
также принудительно после 1000 мс так же происходит запись в лог файл
@keepitsimple
keepitsimple / got-download-stream.js
Created October 6, 2022 13:40 — forked from tsmx/got-download-stream.js
Stream-download a file with filename from response header (content-disposition) via got package.
const got = require('got');
const stream = require('stream');
const fs = require('fs');
const { promisify } = require('util');
const pipeline = promisify(stream.pipeline);
// instantiate the download stream - use options to set authorization header etc. if needed
let downStream = got.stream('https://example.com/download');
downStream.on('response', response => {
@keepitsimple
keepitsimple / spotify-fix.md
Last active August 30, 2021 09:03
Ubuntu mutes Spotify issue fix

Ubuntu mutes Spotify on every system alert / bip / Microsoft Teams sound / etc

Permanent fix

  • Comment out the line with load-module module-role-cork in /etc/pulse/default.pa
  • Reboot OS

Immediate fix

Run in shell

@keepitsimple
keepitsimple / express-pino-healthcheck.js
Created August 20, 2021 08:12
Express.js pino logger configuration; healthcheck
import express from 'express'
import pino from 'pino'
import pinoHttp from 'pino-http'
import { SERVICE_UNAVAILABLE } from 'http-status'
// import { db } from './db'
const logger = pino({ level: process.env.LOG_LEVEL || 'info' })
const PORT = process.env.PORT || 3000
const app = express()
@keepitsimple
keepitsimple / fastest_hash.js
Created June 18, 2021 16:48
Node.js fastest hash function
const crypto = require('crypto');
console.time('hash')
const hash = crypto.createHash('md5').update(str).digest("hex");
console.timeEnd('hash')
console.log(hash)
// sha1 function is much faster on my computer
console.time('hash2')
const hash2 = crypto.createHash('sha1').update(str).digest("base64");
console.timeEnd('hash2')
@keepitsimple
keepitsimple / gist:ff5462acf67ae2cada8a74f95800af50
Created June 6, 2021 15:24
How can you boost your programing speed
- read the "performant programmer" book
- special ergonomic keyboard
- good hardware & fast CPU
- Pomidoro technic
- Rubber duck technic
- Remote debugger
- Ultra wide screen or additional screens
- JetBrains + Shortcuts + Key Promoter + Plugins
- Shell with multiple windows on hotkey
- Oh my Zh with plugins + aliases
@keepitsimple
keepitsimple / downloads.ts
Created March 8, 2021 16:52
Download to file & download to buffer Typescript, Node 12.x, support for redirects. http/https
import fs from 'fs'
import https from 'https'
import http from 'http'
import { basename } from 'path'
import { URL } from 'url'
const TIMEOUT = 10000
const MAX_DOWNLOAD_FILE_SIZE = 1024 * 1024 * 200 // 200MB
export function downloadAsBuffer (url: string): Promise<Buffer> {
@keepitsimple
keepitsimple / download.js
Last active March 6, 2021 15:33 — forked from falkolab/download.js
Download file by http with progress (ES6, promises, NodeJS 12.x)
import fs from 'fs'
import http from 'http'
import { basename } from 'path'
import { URL } from 'url'
const TIMEOUT = 10000
export default function (url, path) {
const uri = new URL(url)
if (!path) {