Skip to content

Instantly share code, notes, and snippets.

@Faheetah
Faheetah / improved.py
Created October 18, 2016 20:58
Ansible stdout callback module with better output, used by output=method in task name
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
import sys
from ansible import constants as C
from ansible.plugins.callback.default import CallbackModule as CallbackModule_default
from ansible.utils.color import colorize, hostcolor
def _color(play):
@bdw
bdw / genius.py
Last active June 18, 2019 23:35
Genius - a roman daemon. This is a python context manager which tries to ensure it is the only process identified by a pidfile.
import os
import fcntl
import signal
import time
import contextlib
class Genius(object):
'''
A genius is basically a roman daemon. It differs from python-daemon
in the following ways:
#!/usr/bin/env python2.7
# -*- coding: UTF-8 -*-
# File: daemonlib.py
"""An example of a Linux daemon written in Python.
Based on http://www.jejik.com/articles/2007/02/a_simple_unix_linux_daemon_in_python/
The changes are:
1 - Uses file open context managers instead of calls to file().
2 - Forces stdin to /dev/null. stdout and stderr go to log files.
@japsu
japsu / mkxtemp.py
Created February 28, 2012 09:01
mkxtemp - a temporary file context manager for use by external processes that need temp files
#!/usr/bin/env python
# Mkxtemp - a temporary file context manager for use by external processes
# Placed in the Public Domain by Santtu Pajukanta <santtu@pajukanta.fi> 2012
from contextlib import contextmanager
from tempfile import NamedTemporaryFile
import os
import unittest
@hvmonteiro
hvmonteiro / Trace.pm
Last active June 20, 2019 22:05
Perl Debug trace messages (like sh -x ) (file: Trace.pm)
# -*- perl -*-
# This content should be added to a (new) file at ".../perllib/Devel/Trace.pm".
# Usage: perl -d:Trace <script.pl>
package Devel::Trace;
$VERSION = '0.12';
$TRACE = 1;
# This is the important part. The rest is just fluff.
import re
import sys
# note, currently doesn't handle:
# Jun 29 00:00:03 host tag: message repeated 3 times: [ 192.168.1.1 - - "POST /api/someendpoint/
r = re.compile(r'(\w{3,}\s+\d{2,}\s+\d{2,}:\d{2,}:\d{2,})\s+([\w-]+)\s+([\w-]+):\s+((\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3},?\s?)+)\s+-\s+-\s+\"(GET|POST|PUT|PATCH|HEAD|DELETE) ((\/[\w_]+)+)\/\??(.*) HTTP\/\d\.\d" (\d{3,}) (\d+|-)')
anonymizers = (
(re.compile(r'(\d+,?)+'), 'id'), # one or more optionally csv separated ids
@mrnohr
mrnohr / 00-header
Last active July 16, 2019 02:06
Raspberry Pi Message of the Day mod
#!/bin/sh
#
# 00-header - create the header of the MOTD
# Copyright (c) 2013 Nick Charlton
# Copyright (c) 2009-2010 Canonical Ltd.
#
# Authors: Nick Charlton <hello@nickcharlton.net>
# Dustin Kirkland <kirkland@canonical.com>
#
# This program is free software; you can redistribute it and/or modify
@janhybs
janhybs / build_status.py
Created March 29, 2019 10:39
Jenkins build status badge with last x builds shown, using flask
#!/bin/python3
# author: Jan Hybs
# example here:
# http://ciflow.nti.tul.cz/status/release/test/5
import urllib.request
import pathlib
import json
import io
from flask import Blueprint, send_file, Response
@sneakyness
sneakyness / MyPlayground.swift
Created November 14, 2018 05:18
Generate a statuslabel.png tinted the color of your MacOS Accent Color and save it in ~/Documents/Shared Playground/Directory/
//: A Cocoa based Playground to present user interface
import AppKit
import PlaygroundSupport
import Foundation
import CoreImage
import ImageIO
let nibFile = NSNib.Name("MyView")
var topLevelObjects : NSArray?
@AliSoftware
AliSoftware / JSONDecoder+Nested.swift
Created January 24, 2019 14:28
Techniques to decode Decodable types that are nested under intermediate keys in a JSON
import Foundation
let json = """
{
"data": {
"items": [
{ "name": "Alice" },
{ "name": "Bob" },
{ "name": "Claudia" }
]