Skip to content

Instantly share code, notes, and snippets.

Bartosz "mastier" Woronicz mastier

View GitHub Profile
@mastier
mastier / land_register_pl.py
Created Jun 13, 2019
Generates land register codes in Poland for given court symbol
View land_register_pl.py
#!/usr/bin/env python3
"""
Generates land register codes in Poland for given court symbol
"""
from itertools import starmap
import operatortype command to continue
import argparse
@mastier
mastier / reassign_shards.sh
Created Apr 10, 2018
reassign unassigned shards in elastic
View reassign_shards.sh
#!/usr/bin/env bash
read -e -p 'Give cluster IP:' -i "$( hostname )" IP
read -e -p 'Give cluster node:' -i "$( hostname )" NODE
read -e -p 'any node suffix?:' -i '_es-01' SUFFIX
IFS=$'\n'
for line in $(curl -s "$IP:9200/_cat/shards" | fgrep UNASSIGNED); do
INDEX=$(echo $line | (awk '{print $1}'))
SHARD=$(echo $line | (awk '{print $2}'))
echo "Reassigning $SHARD $INDEX"
View save mms from Android sms.xml
#!/usr/bin/env python3
# very crude but works ;-)
import bs4
import base64
bs4.BeautifulSoup(open('sms.xml'), 'lxml-xml')
parts=bs.findAll('part')
for part in parts:
if part.parent.parent.findAll('addr', attrs={'address':'+48XXXXXXXXXX'}):
if part.attrs['ct'] not in ('text/plain', 'application/smil'):
@mastier
mastier / huawei_e3372_sms2txt.py
Created Jul 1, 2017
Calculates text response from Huawei E3372 modem SMS in text mode (AT+CMGF=1) to readable one
View huawei_e3372_sms2txt.py
import sys
def huawei_sms2txt(bytes):
"""
Calculates text response from Huawei E3372 modem SMS in text mode (AT+CMGF=1)
to readable one
"""
return ''.join([
y for e,y in enumerate(chr(int(x,16))
for x in re.findall(r'\w{2}', bytes)) if e % 2 != 0])
View ssd total bytes written
# thanks http://www.jdgleaver.co.uk/blog/2014/05/23/samsung_ssds_reading_total_bytes_written_under_linux.html
echo "GB Written: $(echo "scale=3; $(sudo /usr/sbin/smartctl -A /dev/sda | grep "Total_LBAs_Written" | awk '{print $10}') * 512 / 1073741824" | bc | sed ':a;s/\B[0-9]\{3\}\>/,&/;ta')"
@mastier
mastier / givemeironthrone.sh
Created Apr 14, 2016
Root access to shell having script with sudo privileges and ability to modify it
View givemeironthrone.sh
#!/usr/bin/env bash
# This simple script allows you to achieve root shell when you already have access to script
# prerequisites:
# 1. access to write the script
# 2. able to run the scripts sudo as root
ELEVATED_BINARY="$1"
TMPFILE=$( mktemp )
ORIGFILE=$( mktemp )
@mastier
mastier / jenkins_fix_scm.groovy
Last active Mar 21, 2016
Fix Subversion plugin configuration in Jenkins in all jobs
View jenkins_fix_scm.groovy
// Modify SVN related in memory objects
for(item in Hudson.instance.items) {
def scm = item.scm
if((scm instanceof org.jenkinsci.plugins.multiplescms.MultiSCM) ) {
println('##########')
for(s in scm.scms) {
if( s instanceof hudson.scm.SubversionSCM) {
// Change updater
s.workspaceUpdater = new hudson.scm.subversion.UpdateUpdater()
println(s.workspaceUpdater.dump())
@mastier
mastier / jenkins_subversion-plugin-2.5.7-maven.log
Last active Feb 26, 2016
Jenkins subversion-plugin maven log
View jenkins_subversion-plugin-2.5.7-maven.log
[INFO] Scanning for projects...
[WARNING] The POM for org.jenkins-ci.tools:maven-hpi-plugin:jar:1.106 is missing, no dependency information available
[WARNING] Failed to build parent project for org.jenkins-ci.plugins:subversion:hpi:2.5.7
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Jenkins Subversion Plug-in 2.5.7
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-hpi-plugin:1.96:validate (default-validate) @ subversion ---
[INFO]
@mastier
mastier / get_linked_files.py
Last active Feb 18, 2016
Get the list of used files starting from given index.html
View get_linked_files.py
from bs4 import BeautifoulSoup
def get_linked_files(filename, visited=set()):
visited.add(filename)
try:
soup = BeautifulSoup(open(filename).read(), 'html.parser')
tovisit = set([ x.attrs['href'] for x in soup.find_all('a')])
imgs = set([ x.attrs['src'] for x in soup.find_all('img')])
scripts = set([ x.attrs.get('src','') for x in soup.find_all('script')])
links = set([ x.attrs['href'] for x in soup.find_all('link')])
View cmdwrap.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import subprocess
def run_cmd(*args):
process = subprocess.Popen(
args,
stdout=subprocess.PIPE,
You can’t perform that action at this time.