Skip to content

Instantly share code, notes, and snippets.

View AlmightyOatmeal's full-sized avatar

Catlin AlmightyOatmeal

View GitHub Profile
@AlmightyOatmeal
AlmightyOatmeal / python.Files.UTF8.py
Last active May 8, 2018 22:43
Fun with Python and UTF-8 files! Works on Python 2.7.x.
import codecs
import logging
import os
logger = logging.getLogger(os.path.splitext(os.path.basename(__file__))[0])
# NOTE: Python 3.x doesn't have a `unicode()` built-in function.
@AlmightyOatmeal
AlmightyOatmeal / python.Files.Gzip.py
Last active May 8, 2018 22:43
Fun with Python and Gzipped files! Works on Python 2.7.x.
import json
import gzip
import logging
import os
logger = logging.getLogger(os.path.splitext(os.path.basename(__file__))[0])
def write_gzip_file(path, data, overwrite_existing=False, compression_level=9):
@AlmightyOatmeal
AlmightyOatmeal / Kubernetes.Commands.Troubleshooting.md
Last active November 17, 2020 00:56
Useful commands for troubleshooting Kubernetes issues and their respective output
@AlmightyOatmeal
AlmightyOatmeal / SignalFx.Kubernetes.SmartAgent.Example.md
Last active June 21, 2018 20:12
Example of setting-up the SignalFx Agent in Kubernetes 1.10.2 on CentOS 7.4.

SignalFx SmartAgent Kubernetes Example

 ____ ___ ____   ____ _        _    ___ __  __ _____ ____  
|  _ \_ _/ ___| / ___| |      / \  |_ _|  \/  | ____|  _ \ 
| | | | |\___ \| |   | |     / _ \  | || |\/| |  _| | |_) |
| |_| | | ___) | |___| |___ / ___ \ | || |  | | |___|  _ < 
|____/___|____/ \____|_____/_/   \_\___|_|  |_|_____|_| \_\

This is meant as one real-world example of setting up the SignalFx SmartAgent and is not intended to be a replacement for the official documentation. Please make sure that you have read the Kubernetes setup instructions available at https://github.com/signalfx/signalfx-agent/blob/master/docs/kubernetes-setup.md. I am not responsible if you don't read the documentation, you screw something up, or something spontaneously combusts.

@AlmightyOatmeal
AlmightyOatmeal / FreeBSD Boinc Client - Transient HTTP error.md
Last active April 25, 2018 20:57
After noticing boinc was not active for days, all I was receiving was an ambitious "transient HTTP error" message.

Problem: boinc is not running any tasks and logs show errors like:

25-Apr-2018 13:33:27 [World Community Grid] Temporarily failed upload of MCM1_0141526_9856_0_r1232334159_0: transient HTTP error

(that's not very helpful...)

Finding additional information:

Adding debug information to the cc_config.xml

@AlmightyOatmeal
AlmightyOatmeal / Python.Logging.Dictionary-or-JSON.py
Last active February 12, 2020 01:55
Python logging example from dictionary (or loaded JSON) featuring formatting that includes the local timezone, custom log format, logging to both console AND file, and automatically rotating log files.
import logging.config
import time
TZ_NAME = time.tzname[0] if not time.localtime().tm_isdst else time.tzname[1]
# Alternatively, convert the localtime to UTC/GMT but if you use this then update
# the logging formatter because this example is using the local timezone.
# logging_handler.formatter.converter = time.gmtime
# This is kept separate as it can be used to apply a default log level to your
# loggers otherwise you can use a method to change this to debug and apply the
@AlmightyOatmeal
AlmightyOatmeal / Python.ConvertNumberToHumanReadableString.py
Created April 25, 2018 18:40
Convert number to human-readable string based on locale. Additional kwargs passed to locale.format().
import locale
def convert_number_to_human_readable_string(data, fmt=None, grouping=True, **kwargs):
"""Convert number to human-readable string based on locale. Additional kwargs passed to locale.format().
:param data: Some kind of number.
:type data: int, float, long
:param fmt: (optional) Number format. (default: None)
:param grouping: (optional) Take grouping into account. (default: True)
:type grouping: bool
@AlmightyOatmeal
AlmightyOatmeal / Python.JSON.py
Last active February 1, 2024 20:01
Pretty-print a dictionary/list structure in JSON while having the option to use a custom JSON encoder to help with special objects that don't support serialization, such as converting 'datetime' objects to an ISO-formatted string.
import datetime
import decimal
import json
import re
class CustomJSONEncoder(json.JSONEncoder):
"""Custom JSON encoder that does things that shouldn't need to be done."""
def default(self, obj):
@AlmightyOatmeal
AlmightyOatmeal / Python.SignalFx.SignalFlow_Wrapper.py
Last active October 20, 2020 19:15
Wrapper for SignalFx's Python client library for executing SignalFlow programs and returning a dictionary object that can be serialized to JSON. This also features exception handling to retry program text execution which is especially helpful for long-running SignalFlow programs that should be restarted in the event of a failure.
"""
Disclaimer
==========
This has been designed as a solution for a specific task, or set of tasks, by the code author which is outside
the locus of SignalFx supportability. This code is provided as-is and if any support is needed then it should
be provided by the original code author on a best-effort only basis; it cannot be supported through break/fix
support channels.
Synopsis
@AlmightyOatmeal
AlmightyOatmeal / phantom.py
Created November 20, 2017 18:46 — forked from jsok/phantom.py
Use PhantomJS and Python Selenium bindings to take screenshots of websites.
import StringIO
from selenium import webdriver
from PIL import Image
# Install instructions
#
# npm install phantomjs
# sudo apt-get install libjpeg-dev
# pip install selenium pillow