Skip to content

Instantly share code, notes, and snippets.

@ms5
ms5 / simple-rrd-merge.py
Created June 16, 2021 12:19 — forked from arantius/simple-rrd-merge.py
A very simple script to merge multiple RRD files, since none of those available seem to work.
#!/usr/bin/env python
"""Simple script to merge multiple RRD files together.
Accepts any number of RRD file names as arguments. Produces an "rrdtool dump"
style file on stdout. The last RRD file should have a slot for every possible
record in the resulting merged RRD.
Run something like:
$ python simple-merge-rrd.py filea.rrd fileb.rrd filec.rrd | \
@ms5
ms5 / cpu-speed
Created March 19, 2020 15:33 — forked from dreamcat4/cpu-speed
Get and set the max CPU frequency on FreeBSD / FreeNAS / NAS4Free
#!/bin/sh
#
# cpu-speed:
# Requirements - be the root user, FreeBSD 9.2 or higher.
#
# Get or set the CPU frequency. This command with no arguments will
# print the current CPU frequency. CPU may be idling at it's lowest speed.
#
# This command takes 1 optional argument - new MAX cpu freq (in Mhz).
# expressed as an integer number. e.g. "cpu 800" - set max freq 800 Mhz.
@ms5
ms5 / IKEv2.mobileconfig
Created October 26, 2016 13:19 — forked from zqqf16/IKEv2.mobileconfig
strongSwan IKEv2 for iOS without certificate
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>PayloadContent</key>
<array>
<dict>
<key>IKEv2</key>
<dict>
<key>AuthName</key>
import time
def RateLimited(maxPerSecond):
minInterval = 1.0 / float(maxPerSecond)
def decorate(func):
lastTimeCalled = [0.0]
def rateLimitedFunction(*args,**kargs):
elapsed = time.clock() - lastTimeCalled[0]
leftToWait = minInterval - elapsed
if leftToWait>0:
@ms5
ms5 / verbos-argpary-example.py
Last active August 24, 2023 13:37
manipulating log level with python argparse
import argparse
import logging
parser = argparse.ArgumentParser()
parser.add_argument('--verbose', '-v', action='count', default=1)
args = parser.parse_args()
args.verbose = 70 - (10*args.verbose) if args.verbose > 0 else 0
logging.basicConfig(level=args.verbose, format='%(asctime)s %(levelname)s: %(message)s',
@ms5
ms5 / mongobak.py
Last active August 29, 2015 14:14 — forked from theorm/mongobak.py
#! /usr/bin/env python
# -*- coding: utf-8 -*-
import os
import logging
import subprocess
import shutil
import tarfile
import tempfile
import argparse
import re
import shutil
import argparse
from os import path
from sys import stderr
#
# Author: Daxda
# Date: 02.04.2014
# WTF: This is a quick tool I've hacked together to easily remove the meta
import time
def RateLimited(maxPerSecond):
minInterval = 1.0 / float(maxPerSecond)
def decorate(func):
lastTimeCalled = [0.0]
def rateLimitedFunction(*args,**kargs):
elapsed = time.clock() - lastTimeCalled[0]
leftToWait = minInterval - elapsed
if leftToWait>0:
#!/usr/bin/env python
import sys, os, time, atexit
from signal import SIGTERM
class Daemon:
"""
A generic daemon class.
Usage: subclass the Daemon class and override the run() method
# Hacky script for downloading videos from PyVideo and converting them to m4v
# format so they can be synced onto your apple device. Useful if you
# want to see everything that happened at PyCon while commuting.
#
# Requirements:
# * pip install requests BeautifulSoup
# * youtube-dl (from https://github.com/rg3/youtube-dl/) - add this to the
# directory where this script runs and ensure its execute bit is set.
# This was the only YouTube downloader I found that worked. It doesn't
# really have a good Python API so I call it through os.system.