Skip to content

Instantly share code, notes, and snippets.

View AlmightyOatmeal's full-sized avatar

Jamie AlmightyOatmeal

View GitHub Profile
# Base64 encode an image
$ echo "geek_ninja-glow.png" | python -c 'import base64, mimetypes, os, sys; filename=os.path.abspath(sys.stdin.read().strip()); file_mime=mimetypes.guess_type(filename, strict=True)[0]; file_data=base64.b64encode(open(filename, "rb").read()); print(""); print("<img src=\"data:{};base64,{}\">".format(file_mime, file_data))'

<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAA...<snip>...yFo9lYcuhxyAAAAAElFTkSuQmCC">
@AlmightyOatmeal
AlmightyOatmeal / __init__.py
Last active February 9, 2024 16:26
mod_jamie
"""Welcome to the tomorrow of yesterday.
"""
import logging
import urllib3
# Disable `InsecureRequestWarning: Unverified HTTPS request is being made to host '...' ...` messages.
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
# ^ Alternatively, one can set the environmental variable:
# PYTHONWARNINGS="ignore:Unverified HTTPS request"
@AlmightyOatmeal
AlmightyOatmeal / README.md
Created May 15, 2019 20:34 — forked from steve-jansen/README.md
Stop and start Symantec Endpoint Protection on OS X

This script enables you stop and start Symantec Endpoint Protection on OS X

Installation

sudo curl https://gist.githubusercontent.com/steve-jansen/61a189b6ab961a517f68/raw/sep -o /usr/local/bin/sep
sudo chmod 755 /usr/local/bin/sep
sudo chown root:staff /usr/local/bin/sep
@AlmightyOatmeal
AlmightyOatmeal / gist:d5e2f00125cd68d99b3b3533c80378f2
Created January 26, 2019 01:47 — forked from rxaviers/gist:7360908
Complete list of github markdown emoji markup

People

:bowtie: :bowtie: 😄 :smile: 😆 :laughing:
😊 :blush: 😃 :smiley: ☺️ :relaxed:
😏 :smirk: 😍 :heart_eyes: 😘 :kissing_heart:
😚 :kissing_closed_eyes: 😳 :flushed: 😌 :relieved:
😆 :satisfied: 😁 :grin: 😉 :wink:
😜 :stuck_out_tongue_winking_eye: 😝 :stuck_out_tongue_closed_eyes: 😀 :grinning:
😗 :kissing: 😙 :kissing_smiling_eyes: 😛 :stuck_out_tongue:
@AlmightyOatmeal
AlmightyOatmeal / python.mimetypes.py
Last active May 8, 2018 23:04
Fun with Python and mimetypes! Works in Python 2.7.x.
import mimetypes
import os
def find_files(root, accepted_types=None):
"""Walk a path and find files that are a specific type, regardless of extension.
:param root: Path to start walking for files.
:type root: str
:param accepted_types: (optional) List of acceptable mimetypes to match.
@AlmightyOatmeal
AlmightyOatmeal / python.subprocess.py
Last active May 8, 2018 23:01
Fun with Python subprocess! Works on Python 2.7.x.
import json
import logging
import os
import subprocess
logger = logging.getLogger(os.path.splitext(os.path.basename(__file__))[0])
# If you have ever used jq and tried to use it in Python but ran into
@AlmightyOatmeal
AlmightyOatmeal / python.list.fun.py
Last active May 8, 2018 22:42
Fun with Python lists! Works on Python 2.7.x.
def list_chunker(list_obj, chunk_size):
"""Break apart a list into smaller lists as a generator.
:param list_obj: Array of single values in which to be chunkersized.
:type list_obj: list or set
:param chunk_size: Size of the resulting generated lists.
:type chunk_size: int
:return: List of the specified size or last remaining items.
:rtype: list
"""
@AlmightyOatmeal
AlmightyOatmeal / python.dict.fun.py
Last active May 8, 2018 22:41
Fun with Python dictionaries! Works on Python 2.7.x.
def flatten(obj, parent_key=None, sep='.'):
"""Flattens multi-level dictionary to a single-level dictionary.
:param obj: Dictionary object to flatten.
:type obj: dict
:param parent_key: (optional) Prefix for the flattened key. (default: None)
:type parent_key: basestring, str, or unicode
:param sep: (optional) Separator for the nested key names. (default: '.')
:type sep: basestring, str, or unicode
:return: Sexy flattened dictionary.
@AlmightyOatmeal
AlmightyOatmeal / python.locale.py
Last active May 8, 2018 23:03
Fun with Python and locale! Works on Python 2.7.x.
import locale
import logging
import os
logger = logging.getLogger(os.path.splitext(os.path.basename(__file__))[0])
def set_locale(desired_locale=('en_US', 'UTF-8')):
"""Set the local for proper formatting.
@AlmightyOatmeal
AlmightyOatmeal / python.datetime.fun.py
Last active May 8, 2018 23:02
Fun with Python datetime objects! Works on Python 2.7.x.
import datetime
import pytz
def convert_dt_to_milliseconds(dt_obj):
"""Convert datetime object to a Unix epoch timestamp in milliseconds.
:param dt_obj: Datetime object to be converted.
:type dt_obj: instance
:return: Milliseconds since the Unix epoch.