Skip to content

Instantly share code, notes, and snippets.

@csghone
csghone / parse_binary_structures.py
Last active November 28, 2019 11:30
Parse binary data into structures using structures
#!/usr/bin/env python3
# https://github.com/malinoff/structures - not actively developed
import structures
from structures import Repeat, Struct, Bytes, Integer, Contextual, RepeatExactly, BitFields, Const, Computed
class Test(Struct):
const_val = Const(b'AB')
bit_fields = BitFields('b1: 4, b2: 3, b3: 1')
variable_array_length = Integer(1)
#!/usr/bin/env python3
# Usage: python3 download_files_from_slack.py <URL>
import sys
import re
import requests
url = " ".join(sys.argv[1:])
token = 'SLACK_TOKEN'
from mako.template import Template
from mako.lookup import TemplateLookup
from mako import exceptions
from lxml import etree
def get_pretty_xml(xml_string, xml_declaration=True):
parser = etree.XMLParser(remove_blank_text=True, recover=True)
root = etree.fromstring(xml_string, parser)
pretty_xml = etree.tostring(
@csghone
csghone / rsync_on_flaky_networks.sh
Last active September 9, 2022 03:18
RSYNC on bad networks
# Sample command:
# rsync_on_flaky_networks.sh 192.168.101.102:logs_20200706* dst_folder/
SRC="$1"
DST="$2"
if [ "$SRC" == "" ]; then
echo "Invalid arguments. Usage: $0 <SRC> <DST>"
fi
if [ "$DST" == "" ]; then
echo "Invalid arguments. Usage: $0 <SRC> <DST>"

Tested mostly with 14.04 - but should work with minor tweaks on higher versions

Graphical Environment Setup

# In case your EC2 installation didn't have any GUI packages/X server/etc.
# Ref: https://stackoverflow.com/questions/25657596/how-to-set-up-gui-on-amazon-ec2-ubuntu-server
sudo apt-get install gnome-panel gnome-settings-daemon metacity nautilus gnome-terminal gnome-desktop-environment gnome-theme* gnome-icon-theme

TurboVNC Installation steps

@csghone
csghone / print_slack_history.py
Created June 28, 2019 07:00
Print Slack History for slack archive
import os
import sys
import json
import datetime
import math
USER_FILE = sys.argv[1] # users.json
CHANNEL_DIR = sys.argv[2] # folder of channel containing message jsons
users = json.load(open(USER_FILE))
@csghone
csghone / selenium_wrapper_class.py
Created May 7, 2019 10:31
Selenium Wrapper Class for Python
#!/usr/bin/env python3
# Setup and Usage:
# - sudo -H pip3 install selenium pytz retrying pandas bs4`
# - Download geckodriver and copy to same directory as this file
# - python3 get_ransquawk_data.py
import os
import sys
import traceback
sudo ip -s -s neigh flush all
sudo systemd-resolve --flush-caches
sudo ip -s -s neigh flush all
#!/usr/bin/env python3
"""
eg:
python3 ./sample_python.py -w -x opt1 -y 3 -z 1 2 3 -f ~/.bashrc -d 20190101 --inp_datestring 20191101
"""
from __future__ import print_function
import os
import sys
import argparse
@csghone
csghone / selenium_example.py
Last active September 27, 2018 06:05
Example Selenium Usage
#!/usr/bin/env python3
# Setup and Usage:
# - sudo -H pip3 install selenium`
# - Download geckodriver from https://github.com/mozilla/geckodriver/releases
# - export PATH=$PATH:<directory_of_geckodriver>`
# - python3 selenium_example.py
import os