Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View sergray's full-sized avatar

Sergey Panfilov sergray

View GitHub Profile
#!/bin/bash
rrdtool graph power.png --vertical-label=W*h --font=DEFAULT:11:Arial -w 900 -h 600 \
DEF:apower=pcv.rrd:power:AVERAGE CDEF:whpower=apower,1000,\* LINE2:whpower#FF0000
#!/usr/bin/env python
from __future__ import print_function
from datetime import datetime
from subprocess import call
from mercury206 import commands, communications, config
@sergray
sergray / rrdenergy.py
Created May 26, 2014 02:45
Store energy consumption in RRD files
#!/usr/bin/env python
from datetime import datetime
from subprocess import call
from mercury206 import commands, communications, config
def update_rrd(path, values):
#!/usr/bin/env python
"""Describe EC2 instances bound to DNS name. Lookup CNAME of DNS,
which can point to ELB or EC2 instance. Get info from AWS API.
DNS names should be passed as arguments to the script.
Valid AWS API credentials must be configured, see
http://docs.pythonboto.org/en/latest/getting_started.html#configuring-boto-credentials
"""
from __future__ import print_function
@sergray
sergray / check_ssl_certificate.py
Last active January 2, 2016 01:59
python script checking SSL certificates, taken from superuser.com
#!/usr/bin/env python
"""
Usage: check_ssl_certificate.py -H <host> -p <port> [-m <method>]
[-c <days>] [-w <days>]
-h show the help
-H <HOST> host/ip to check
-p <port> port number
-m <method> (SSLv2|SSLv3|SSLv23|TLSv1) defaults to SSLv23
-c <days> day threshold for critical
-w <days> day threshold for warning
@sergray
sergray / report_avangard_transit.py
Created October 29, 2013 12:37
Python PDF utililties
# coding=utf8
"""
Генератор CSV отчета из PDF отчетов банка Авангард о поступлении средств на
транзитный валютный счет.
По умолчанию читает из стандартного ввода данные извлеченные из PDF при помощи
textpdf.py утилиты.
Генерируемый CSV отчет печатается в стандартный вывод и включает следующие колонки:
* date - дата получения средств
@sergray
sergray / list_of_lists.py
Created July 23, 2013 15:20
Python list of lists gotcha, showing that it's not a good idea to create 2d array with multiplication of lists. Inner lists turns out to be the references to the same object.
In [1]: list_of_lists = [['#'] * 4] * 4
In [2]: list_of_lists
Out[2]:
[['#', '#', '#', '#'],
['#', '#', '#', '#'],
['#', '#', '#', '#'],
['#', '#', '#', '#']]
In [3]: map(id, list_of_lists)
@sergray
sergray / django_snippet.py
Created September 14, 2012 06:54
Print RST represention of Django model
def text_model(M):
print M.__name__
print '~' * len(M.__name__)
print '-', '\n- '.join('%s: %s' % (f.name, f.__class__.__name__) for f in M._meta.fields)
@sergray
sergray / merge_logs.py
Created September 10, 2012 11:17
Script for combining access logs and outputting their records sorted by time
#!/usr/bin/env python
"""
Combines provided access logs and outputs records sorted by
time of record.
Time of the record is expected to be the forth element in the
record and must have +0000 timezone.
"""
import logging
@sergray
sergray / gist:2856568
Created June 2, 2012 04:27
make pprint speak your language in python console
# assuming you have UTF-8 locale
import pprint
orig_format = pprint.PrettyPrinter._format
def patched_format(self, object, stream, indent, allowance, context, level):
if isinstance(object, unicode):
stream.write("u\'")
stream.write(object.encode('utf8'))
stream.write("'")