Skip to content

Instantly share code, notes, and snippets.

@kowalcj0
kowalcj0 / SeleniumBrowserEnumWithHelpers.py
Created December 7, 2017 12:36
handy python enum for various browsers with some helpers that allow to toggle some hidden features
from enum import Enum
from selenium.webdriver import ChromeOptions, FirefoxProfile
class Browser(Enum):
CHROME = "chrome"
FIREFOX = "firefox"
IE = "ie"
PHANTOMJS = "phantomjs"
@kowalcj0
kowalcj0 / get_docker_repo_tags.sh
Created February 28, 2018 10:27
list all the available image tags for a docker hub repo
wget -q https://registry.hub.docker.com/v1/repositories/circleci/python/tags -O - | sed -e 's/[][]//g' -e 's/"//g' -e 's/ //g' | tr '}' '\n' | awk -F: '{print $3}'
@kowalcj0
kowalcj0 / sync.sh
Last active March 26, 2018 12:07
notes from installing syncthing in freebsd 10.3 jail
# 1 - create syncthing jail
# 2 - add storage
# install bash and syncthing
pkg install bash
pkg install syncthing
# add syncthing user
```
@kowalcj0
kowalcj0 / urls-checker.py
Created March 27, 2018 11:03
Modified version of fetch function with semaphore created by: Paweł Miech https://pawelmhm.github.io/asyncio/python/aiohttp/2016/04/22/asyncio-aiohttp.html
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""Modified version of fetch function with semaphore created by: Paweł Miech
src: https://pawelmhm.github.io/asyncio/python/aiohttp/2016/04/22/asyncio-aiohttp.html
"""
import argparse
import asyncio
import sys
from argparse import Namespace
from asyncio import Semaphore
@kowalcj0
kowalcj0 / parallel_pa11y.sh
Last active June 12, 2018 17:38
run pa11y accessibility scan in parallel and save report for each URL in html file
sudo dnf install parallel
npm install pa11y pa11y-reporter-html
# the Perl expression {= s:[/\:\?\&\=]:-:g; =} will replace all special charachers '/:?&' in report filename with '-'
parallel 'pa11y --reporter=html {} > {= s:[/\:\?\&\=]:-:g; =}.html' < urls.txt
function cheat() {
# ${1} - is the language/dmbs/etc
# ${*:2} - your query
# sed 's/ /+/g' - will replace spaces with `+`
curl https://cheat.sh/${1}/`echo "${*:2}" | sed 's/ /+/g'`
}
# example usage:
# cheat python recursion
# cheat python open files
@kowalcj0
kowalcj0 / trim.sh
Created September 8, 2018 22:37
Trim videos losslessly with ffmpeg
alias trim=trim
function trim() {
if [ "$#" != "3" ]; then
echo "Please provide all 3 arguments: 'filename start duration'"
return 1
fi
video="${1}"
filename="${1%.*}"
extension="${1##*.}"
@kowalcj0
kowalcj0 / stabilize.sh
Created September 8, 2018 22:40
Stabilise shaky video with ffmpeg and vid.stab
alias stabilize=stabilize
function stabilize() {
type ffmpeg >/dev/null 2>&1 || { echo >&2 "ffmpeg is required but it's not installed."; return 1; }
video="${1}"
filename="${1%.*}"
extension="${1##*.}"
output="${filename}-stabilized.${extension}"
# calculate transformation vectors
ffmpeg -nostdin -hide_banner -i "${video}" -vf vidstabdetect=stepsize=6:shakiness=8:accuracy=15:result=transform_vectors.trf -f null -
@kowalcj0
kowalcj0 / extract_music_urls.py
Created October 26, 2018 23:28
Extract links to music websites from Mastodon's outbox.json and download them with youtube-dl in parallel with covers and metadata
#! /usr/bin/python
"""Extract links to music websites from Mastodon's outbox.json
outbox.json contains all of your toots
"""
import json
from bs4 import BeautifulSoup as Soup
def extract_music_urls():
with open("outbox.json") as f:
#!/usr/bin/env python3
import os
import shutil
def what_is_inside(types) -> str:
result = ""
if "mp3" in types and "flac" in types:
result = "both"
if "mp3" in types and not "flac" in types: