Skip to content

Instantly share code, notes, and snippets.

View ionelmc's full-sized avatar
🙃
wat

Ionel Cristian Mărieș ionelmc

🙃
wat
View GitHub Profile
@ionelmc
ionelmc / vbox-shutdown.py
Last active January 9, 2025 12:20
VirtualBox automatic shutdown cleaner. Runs in the "notification icon area". When closed by windows it waits for VMs to shutdown (acpi) and if it doesn't work it tries to suspend the VMs.
import logging
import subprocess
import time
import sys
import win32con
import win32gui_struct
import os
try:
import winxpgui as win32gui
except ImportError:
@ionelmc
ionelmc / join.py
Created November 29, 2013 14:12
join that extends and revokes
def join(resultset, task_options=(), queue_results=False, propagate=True,
interval=0.5, cleanup=None):
pending_results = deque(resultset.results)
resultset = ResultSet(list(resultset.results))
completed_results = []
def handle_abort():
logger.warning(
"task_control.join is aborting ! Revoking taskset %s and calling cleanup function %r.",
resultset,
cleanup
@ionelmc
ionelmc / dabblet.css
Created November 29, 2013 09:30
The first commented line is your dabblet’s title
/**
* The first commented line is your dabblet’s title
*/
background: #f06;
background: linear-gradient(45deg, #f06, yellow);
min-height: 100%;

Steps to reproduce

In first terminal

./bootstrap.sh
./app.py worker --events --purge --loglevel=DEBUG --concurrency 5
@ionelmc
ionelmc / settings.py
Last active December 27, 2015 12:49
Dead-simple Django SQL logging
import sys
try:
from sqlparse import format as sqlformat
except ImportError:
sqlformat = lambda s, reindent=None: s
from traceback import format_stack
class WithStacktrace(object):
def __init__(self, skip=[], limit=5):
self.skip = [__name__, 'logging']
def monkeypatch(mod, what):
"""
Patch function named <what> from module <mod> to run the decorated function after <what> completes.
Eg::
@monkeypatch(os, 'forkpty')
def patched_forkpty(pid_fd):
pid, fd = pid_fd
if not pid:
val = cache.get(key)
if val:
return val
else:
with cache.lock(key):
val = cache.get(key)
if val:
return val
else:
#!/usr/bin/env python
"""
jngo -- The unhealthily compressed Django application.
Usage: ./jngo.py
Assuming a working install of Django (http://djangoproject.com/) and SQLite
(http://sqlite.org), this script can be executed directly without any other
preparations -- you don't have to do `setup.py install`, it doesn't
need to be on your Python path, you don't need to set DJANGO_SETTINGS_MODULE,
#!/bin/bash -eEx
if ! which gpg-agent; then
sudo apt-get install gnupg-agent
fi
if ! which pull-lp-source; then
sudo apt-get install ubuntu-dev-tools
fi
gpg-agent || eval `gpg-agent --daemon`
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Droopy (http://stackp.online.fr/droopy)
# Copyright 2008-2012 (c) Pierre Duquesne <stackp@online.fr>
# Licensed under the New BSD License.
# Changelog
# 20120108 * Taiwanese translation by Li-cheng Hsu.
# 20110928 * Correctly save message with --save-config. Fix by Sven Radde.