Skip to content

Instantly share code, notes, and snippets.

@kowalcj0
kowalcj0 / convert_any_text_file_to_utf8_file_like_object.py
Last active November 27, 2021 12:31
Convert any text file into UTF-8 file like object
import chardet # https://pypi.python.org/pypi/chardet
def file_to_utf8(f_name):
"""Convert any file into UTF-8 file like object.
This conversion method is not perfect, because chardet doesn't detect the char set with 100% accuracy.
You'd have to base the decision to do the conversion on the confidence level (raging from 0 to 1) returned by the detect()
detect() returns a dictionary containing the auto-detected character encoding and a confidence level from 0 to 1.
"""
with open(f_name, 'rb') as f:
@kowalcj0
kowalcj0 / example_async_tornado-couchdb.py
Last active August 29, 2015 14:09
Example tornado coroutines that asynchronously save and retrieve document from a CouchDB
# -*- coding: utf-8 -*-
import couch
from tornado import ioloop, gen
def _setup(db_name="test"):
return couch.AsyncCouch(db_name)
@gen.coroutine
@kowalcj0
kowalcj0 / gist:7681a6b21719c373caa1
Created January 7, 2015 16:43
Sort behave steps by the execution time
# Helps to find out which one takes a lot of time to run.
awk '$NF ~ /^[0-9]\.[1-9]/ { print $NF, $0 }' behave_result.log | sort -n -r
@kowalcj0
kowalcj0 / RecyclerViewMatcher.kt
Last active September 5, 2016 11:24
A Kotlin implementation of the RecycleViewMatcher for Espresso
import android.content.res.Resources;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import org.hamcrest.Description;
import org.hamcrest.Matcher;
import org.hamcrest.TypeSafeMatcher;
/**
* @author https://github.com/ebelli
@kowalcj0
kowalcj0 / README.md
Created September 27, 2016 10:11
How to deal with github's 2FA when you're forced to use https instead of ssh

Generate the access token on github https://github.com/settings/tokens (repo level is enough to get push and pull working) Then create a .netrc file in your home dir like so:

    machine github.com
    login your_github_username
    password xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Replace password with the token. Ta-da! Boom! ps. Windows doesn't like the filename .netrc so you have to call it _netrc

@kowalcj0
kowalcj0 / container_id.sh
Created November 9, 2016 11:40
Get the docker container ID from within it
#!/usr/bin/env bash
container_id=$(cat /proc/self/cgroup | grep -o "docker.*" | head -n 1 | cut -d/ -f 2)
echo ${container_id}
@kowalcj0
kowalcj0 / gist:971a2ba49f2f40aea43379c2d95a1c66
Created November 13, 2016 12:58
CSL vertical mouse multimedia key bindings
# CSL vertical mouse
# https://www.amazon.co.uk/Wireless-vertical-ergonomic-optical-design/dp/B00JODVD5K
sudo apt-get install xautomation xinput xbindkeys xdotool
vi ~/.xbindkeysrc
"/usr/bin/xdotool key --clearmodifiers XF86AudioPrev"
b:8 + Release
"/usr/bin/xdotool key --clearmodifiers XF86AudioNext"
@kowalcj0
kowalcj0 / mts2mp4.sh
Created January 29, 2017 14:08
Convert and deinterlace MTS to mp4 with ffmpeg and metadata
for f in *.MTS
do
ffmpeg -i "${f}" \
-deinterlace \
-acodec copy \
-metadata album="Trip to ..." \
-metadata title="Aquario Encantado - $(basename ${f} .MTS)" \
-metadata artist="you, me, she and him" \
-metadata year="2017" \
-metadata date="2017-01-04" \
@kowalcj0
kowalcj0 / mtsac32mp4aac.sh
Created January 29, 2017 14:46
Covert and deinterlace mts with ac3 to mp4 with aac
for f in *.MTS
do
ffmpeg -i "${f}" \
-deinterlace \
-acodec aac -b:a 256k -strict -2 \
-metadata album="Trip to ..." \
-metadata title="Aquario Encantado - $(basename ${f} .MTS)" \
-metadata artist="you, me, she and him" \
-metadata year="2017" \
-metadata date="2017-01-04" \
@kowalcj0
kowalcj0 / Python
Created June 27, 2017 09:52
non-capturing groups in Python Behave step definition
@given("User has (?:his|her) picture uploaded")
def step_impl(context):
pass