Skip to content

Instantly share code, notes, and snippets.

@methane
methane / gist:2185380
Created March 24, 2012 17:28
Tornado Example: Delegating an blocking task to a worker thread pool from an asynchronous request handler
from time import sleep
from tornado.httpserver import HTTPServer
from tornado.ioloop import IOLoop
from tornado.web import Application, asynchronous, RequestHandler
from multiprocessing.pool import ThreadPool
_workers = ThreadPool(10)
def run_background(func, callback, args=(), kwds={}):
def _callback(result):
@jclulow
jclulow / 00_info.md
Created May 5, 2012 23:46
SmartOS rc.local

So, to get something like /etc/rc.local you can use the custom SMF import facility. (See the source for more information about how this actually works.)

/opt is mounted out of zones/opt by default. You can create a directory /opt/custom/smf and populate it with SMF manifests. Any manifests you put in there will be imported by SmartOS when it boots. Below is an example SMF manifest that simply starts /opt/custom/bin/postboot, a self-explanatory shell script that you can use like /etc/rc.local.

Note that it would likely be better to customise and respin your own images, as putting a bunch of platform state in the zones pool undoes some of the benefits of the ramdisk platform architecture that SmartOS has.

@nhoad
nhoad / gist:8966377
Last active March 2, 2023 09:30
Async stdio with asyncio
import os
import asyncio
import sys
from asyncio.streams import StreamWriter, FlowControlMixin
reader, writer = None, None
@asyncio.coroutine
def stdio(loop=None):
@tristanfisher
tristanfisher / Ansible-Vault how-to.md
Last active December 27, 2022 05:17
A short tutorial on how to use Vault in your Ansible workflow. Ansible-vault allows you to more safely store sensitive information in a source code repository or on disk.

Working with ansible-vault


I've been using a lot of Ansible lately and while almost everything has been great, finding a clean way to implement ansible-vault wasn't immediately apparent.

What I decided on was the following: put your secret information into a vars file, reference that vars file from your task, and encrypt the whole vars file using ansible-vault encrypt.

Let's use an example: You're writing an Ansible role and want to encrypt the spoiler for the movie Aliens.

@sigmaris
sigmaris / python3-ldap-gssapi.py
Created September 10, 2014 09:48
Authenticate to LDAP using python3-ldap and python-gssapi
import gssapi
from ldap3 import Connection, SASL_AVAILABLE_MECHANISMS
from ldap3.protocol.sasl.digestMd5 import sasl_digest_md5
from ldap3.protocol.sasl.external import sasl_external
from ldap3.protocol.sasl.sasl import send_sasl_negotiation, abort_sasl_negotiation
SASL_AVAILABLE_MECHANISMS.append('GSSAPI')
def sasl_gssapi(connection, controls):
@rasschaert
rasschaert / arch_bootstrap.bash
Last active July 27, 2022 12:43
Shell script that performs the installation of Arch Linux the way I like it.
#!/bin/bash
bootstrapper_dialog() {
DIALOG_RESULT=$(dialog --clear --stdout --backtitle "Arch bootstrapper" --no-shadow "$@" 2>/dev/null)
}
#################
#### Welcome ####
#################
bootstrapper_dialog --title "Welcome" --msgbox "Welcome to Kenny's Arch Linux bootstrapper.\n" 6 60
@jblachly
jblachly / cloudinit-tips.md
Last active March 9, 2022 07:49
SmartOS (standalone) cloudinit setup for KVM images

The following keys, when placed in the customer_metadata section of the VM definition JSON will effect the specified behaviour:

smartos key corresponds to cloudinit key effect
hostname local-hostname
root_authorized_keys public-keys copies to /root/.ssh and default user ~/.ssh (e.g., ubuntu)
user-script user-script Executed each boot
user-data legacy-user-data
cloud-init:user-data user-data Evaluated by cloud-init once at VM creation only
iptables_disable iptables_disable ?
@InsanePrawn
InsanePrawn / container_dhcp.network
Last active March 7, 2024 18:11
block device passthrough into systemd-nspawn for testing the munin smartctl plugin
[Match]
Name=host*
[Network]
DHCP=yes
@bradmontgomery
bradmontgomery / single_dispatch_example.py
Created August 23, 2016 17:08
Example of single dispatch in python. This is seriously cool stuff.
"""
Playing with python's single dispatch.
See: https://hynek.me/articles/serialization/
See also PEP 443: https://www.python.org/dev/peps/pep-0443/
"""
from datetime import datetime
from functools import singledispatch
@acundari
acundari / traefik-auth.conf
Last active December 6, 2022 09:41
Traefik fail2ban
# /etc/fail2ban/filter.d/traefik-auth.conf
[Definition]
failregex = ^<HOST> \- \S+ \[\] \"(GET|POST|HEAD) .+\" 401 .+$