Skip to content

Instantly share code, notes, and snippets.

@conrad784
conrad784 / read_nonblocking.py
Created December 14, 2018 15:50
nonblocking read function for python, e.g. for named pipes
def read_nonblocking(path, bufferSize=100, timeout=.100):
import time
"""
implementation of a non-blocking read
works with a named pipe or file
errno 11 occurs if pipe is still written too, wait until some data
is available
"""
grace = True
@conrad784
conrad784 / initRemoteGit.sh
Created April 25, 2018 08:02
create a git repository on a ssh host
#!/bin/sh
GITHOST="myGit" # remote server name (for ssh)
REMOTE="myGit" # remote name in git config
GITFOLDER="git"
MYUSERNAME=$USER # assume we want to take current user account, change this at will
if [ -z "$1" ]; then
FOLDERNAME=$( basename $(pwd))
@conrad784
conrad784 / get_all_outputs.py
Last active March 22, 2018 20:20
function to get stderr in other variable as stdout and also possible to print the output in real-time
def subprocess_get_all_outputs(cmd, shell=True, print_stdout=True, print_stderr=True):
"""
behaves like a subprocess.check_output() where you can get print output
of stdout and stderr and both also in variables
"""
import subprocess
out = b''
err = b''
p = subprocess.Popen(cmd, shell=shell, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
while True:
@conrad784
conrad784 / bootstrap-config.sh
Last active March 25, 2018 11:16
bootstrap config files
#!/bin/sh
# found here: https://developer.atlassian.com/blog/2016/02/best-way-to-store-dotfiles-git-bare-repo/
# tried to improve to work with subfolders, but something is wrong, sometimes have to run twice
git clone --bare git@github.com:conrad784/dotfiles.git $HOME/.cfg
function config {
/usr/bin/git --git-dir=$HOME/.cfg/ --work-tree=$HOME $@
}
function mv_fullpath(){
copy_file="$1";
#echo "cf: $copy_file";
@conrad784
conrad784 / queryIP.sh
Last active April 25, 2018 08:04
query your ipv4/6 address and print the name of the network you are in
#!/bin/sh
IPV4=$(curl -s -4 icanhazip.com)
IPV6=$(curl -s -6 icanhazip.com)
PTR4=$(curl -s -4 icanhazptr.com)
PTR6=$(curl -s -6 icanhazptr.com)
NETNAME=$(whois $IPV4 | grep netname | rev | cut -d ' ' -f1 | rev)
echo "IPV4: $IPV4"
echo "IPV6: $IPV6"
@conrad784
conrad784 / bulkConvert.sh
Created February 22, 2018 21:11
convert mkv movie files to h264 compressed versions in 720p
#!/bin/bash
STOREDIR="smaller/"
OUTPUTFORMAT=".mkv"
SEARCHPATH="*"
mkdir -p ${STOREDIR}
if [ -z "$1" ]
then
echo "No arguments given"
@conrad784
conrad784 / removeDuplicates.py
Created February 21, 2018 09:13
python script to scan directory for duplicate files and keeping the latest file
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# (C) 2018 Conrad Sachweh
"""NAME
%(prog)s - <description>
SYNOPSIS
%(prog)s [--help]

Keybase proof

I hereby claim:

  • I am conrad784 on github.
  • I am conradsachweh (https://keybase.io/conradsachweh) on keybase.
  • I have a public key ASDRXVO1YWztQvTBJ3symqrBToi6y_6CT4qY9zwqf8ZqEAo

To claim this, I am signing this object: