Skip to content

Instantly share code, notes, and snippets.

@dmitrydyomin
dmitrydyomin / teletail
Last active December 9, 2024 12:26
Tail file and send lines to Telegram
#!/bin/bash
# https://stackoverflow.com/a/48779000
# https://dev.to/nathannosudo/bash-script-to-send-a-message-in-telegram-from-your-terminal-20c7
if [ "$#" -ne 1 ]; then
echo "Usage: API_TOKEN=123 CHAT_ID=456 teletail /var/log/test.log"
exit 0
fi
@dmitrydyomin
dmitrydyomin / rotw-cut.sh
Created September 20, 2024 05:23
Recipe of the week
#!/bin/bash
dir=s1
out=out
mkdir -p $out/$dir
re='^[0-9]+$'
for filename in $dir/*; do
@dmitrydyomin
dmitrydyomin / build-imgproxy.sh
Last active January 14, 2022 10:45
Build Imgproxy for Linux using Docker
#!/bin/bash
set -e
TAG=imgproxy-builder
docker build -t $TAG - << EOF
FROM golang:latest
RUN apt update && apt install -y libvips-dev
WORKDIR /src
RUN git clone https://github.com/imgproxy/imgproxy.git
document.querySelectorAll('.comment').forEach(el => {
const score = parseInt(el.querySelector('.voting-wjt__counter').innerText.replace('–', '-'));
if (Math.abs(score) < 2) {
el.remove();
}
});
@dmitrydyomin
dmitrydyomin / react-i18n.js
Created January 29, 2020 12:13
Simple i18n provider and hook for React
import React, { createContext, useContext, useState } from 'react';
import PropTypes from 'prop-types';
import en from './en';
const TranslationContext = createContext();
export const useTranslation = () => useContext(TranslationContext);
const data = {
@dmitrydyomin
dmitrydyomin / index.php
Created December 12, 2018 14:11
PHP Zend 1 click to open debug trace file in VS Code for unhandled errors
<?php
function dd()
{
echo('<pre>');
call_user_func_array('var_dump', func_get_args());
exit();
}
require_once '../vendor/autoload.php';
@dmitrydyomin
dmitrydyomin / serve.sh
Created April 26, 2018 08:19
PHP dev server script with SSH tunnel
#!/bin/bash
DB_HOST=...
if [[ $1 == --tunnel ]] || [[ $1 == -T ]]; then
ssh -NL 3306:127.0.0.1:3306 $DB_HOST &
PID=$!
echo "ssh pid: $PID"
fi
@dmitrydyomin
dmitrydyomin / ffgif.sh
Created August 22, 2016 07:15
Convert video to animated GIF using FFmpeg
#!/bin/sh
ffmpeg -y -i source.mp4 -vf fps=5,scale=480:-1:flags=lanczos,palettegen palette.png
ffmpeg -i source.mp4 -i palette.png -filter_complex "fps=5,scale=480:-1:flags=lanczos[x];[x][1:v]paletteuse" output.gif
@dmitrydyomin
dmitrydyomin / flac2mp3.sh
Created June 17, 2016 19:46
Bash script to convert all flac files in dir to mp3
#!/bin/bash
for i in *.flac ; do
ffmpeg -i "$i" -acodec libmp3lame -ab 256k -y "$(basename "${i/.flac}").mp3"
sleep 1
done
@dmitrydyomin
dmitrydyomin / q3la.py
Last active September 21, 2015 10:31
Simple Quake III Arena log analyser (scores only)
import re
with open("games.log", "r") as myfile:
data = myfile.read()
results = {}
players = {}
for time, score, ping, name in re.findall('(\d+:\d+)\s+score:\s+([-\d]+)\s+ping:\s+(\d+)\s+client:\s+\d+\s+(.*)', data):
if not time in results: