Skip to content

Instantly share code, notes, and snippets.

@dmitrydyomin
dmitrydyomin / backup_mysql.sh
Last active August 29, 2015 14:05
MySQL backup script
#!/bin/bash
if [ $# == 1 ] && [ $1 != "--daily" ]; then
declare -a databases=("$1")
else
declare -a databases=("db1 db2")
fi
for database in "${databases[@]}"
do
@dmitrydyomin
dmitrydyomin / apache-files-download.py
Last active August 29, 2015 14:25
Downloads files from Apache server with +Indexes option to a local folder. Restores badly encoded CP-1251 filenames. To restart the download just run it once again.
#!/Library/Frameworks/Python.framework/Versions/2.7/bin/python
from bs4 import BeautifulSoup
import urllib2, urllib
import re, os
# create a password manager
password_mgr = urllib2.HTTPPasswordMgrWithDefaultRealm()
baseurl = "http://example.com/files/"
user = 'foo'
password = 'bar'
@dmitrydyomin
dmitrydyomin / simple_git_deploy.sh
Created September 9, 2015 17:23
Simple website deploy from GIT repo. Just exports provided ref to a temp directory, then swaps directories and removes the old one.
#!/bin/bash
if [ "$#" -ne 3 ]; then
echo "Usage: deploy REPO REF DIR"
echo "e.g. deploy /opt/git/example.git master /var/www/example.com"
exit
fi
REPO=$1
REF=$2
@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:
@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 / 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 / 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 / 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 / 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 = {
document.querySelectorAll('.comment').forEach(el => {
const score = parseInt(el.querySelector('.voting-wjt__counter').innerText.replace('–', '-'));
if (Math.abs(score) < 2) {
el.remove();
}
});