Skip to content

Instantly share code, notes, and snippets.

View martinrusev's full-sized avatar
🌱
01010110

Martin Rusev martinrusev

🌱
01010110
  • Berlin, Germany
View GitHub Profile
@martinrusev
martinrusev / amonplugin.py
Last active August 29, 2015 13:57
Custom Amon Plugin
from amonagent.plugin import AmonPlugin
class MyCustomPlugin(AmonPlugin):
def collect(self):
"""
The agent collects and sends all the metrics defined in this function
"""
@martinrusev
martinrusev / etc.amonagent
Last active August 29, 2015 13:57
Plugin directory structure
├── amonagent
│   ├── plugins
│   │   ├── apache
│   │   │   ├── apache.conf.example
│   │   │   ├── apache.py
│   │   │   ├── README.md
│   │   │   └── requirements.txt
│   └── plugins-enabled
│   └── apache.conf
@martinrusev
martinrusev / counters-example.py
Created March 16, 2014 10:39
Counters example
self.counter('opcounters.insert', 93)
self.counter('opcounters.update', 17)
self.counter('opcounters.command', 320)
self.counter('opcounters.getmore', 0)
@martinrusev
martinrusev / haiku.py
Created March 27, 2014 10:31
Heroku like haiku random name generator
import random
adjs = [
"autumn", "hidden", "bitter", "misty", "silent", "empty", "dry", "dark",
"summer", "icy", "delicate", "quiet", "white", "cool", "spring", "winter",
"patient", "twilight", "dawn", "crimson", "wispy", "weathered", "blue",
"billowing", "broken", "cold", "damp", "falling", "frosty", "green",
"long", "late", "lingering", "bold", "little", "morning", "muddy", "old",
"red", "rough", "still", "small", "sparkling", "throbbing", "shy",
"wandering", "withered", "wild", "black", "young", "holy", "solitary",
@martinrusev
martinrusev / lazy_context_processor.py
Created April 3, 2014 17:17
Django lazy context processor
# https://djangosnippets.org/snippets/3011/
# Sometimes you have context variables that are needed on many pages in a site,
# but not all. You only want them to be evaluated when actually needed, especially
# if they are expensive calculations that do DB queries etc. The pattern to use is
# shown: put a callable into the context, not the final value, and also wrap the
# callable with memoize_nullary.
#
# This solution uses the fact that the Django template language will detect and
# call any callables when they are referred to. So, if a template contains:
#
@martinrusev
martinrusev / package_updates_ubuntu.py
Created April 20, 2014 10:17
Checks for available package updates in Ubuntu
import subprocess
import re
packages_for_upgrade = subprocess.Popen(["apt-get",'-q','-V', '-s', 'upgrade', '2>&1'], stdout=subprocess.PIPE, close_fds=True,
).communicate()[0]
upgrades_index = False
for index, line in enumerate(packages_for_upgrade.splitlines()):
if line.startswith('The following packages will be upgraded'):
@martinrusev
martinrusev / package_updates_centos.py
Created April 20, 2014 12:52
Checks for available package updates in CentOS
# Run in Docker
# docker run -v /home/martin/temp/:/var/scripts -i -t centos:latest python /var/scripts/packagecentos.py
import subprocess
import re
installed_packages_dict = {}
installed_packages = subprocess.Popen(["yum",'--color=never','list', 'installed'], stdout=subprocess.PIPE, close_fds=True,
@martinrusev
martinrusev / virtualbox_cleanup.sh
Created May 20, 2014 12:14
Cleanup before installing VirtualBox guest additions
rm /usr/lib64/VBoxGuestAdditions
rm /usr/share/VBoxGuestAdditions
rm -rf /opt/VBoxGuestAdditions-4.3*
@martinrusev
martinrusev / react-notifications.js
Created May 26, 2014 06:09
React notificitations
/** @jsx React.DOM */
var Notification = React.createClass({
componentDidMount: function() {
setTimeout(function() {
React.unmountComponentAtNode(document.getElementById('react-container'));
}, 3000);
},
"use strict";
var app = angular.module('RickshawApp', [])
.factory('RickshawDataService', function($http){
return {
GetData: function() {
return $http.get('http://192.168.174.1:8080/data.json/?callback=JSON_CALLBACK')
.then(function(result) {
return result.data;
});
} // get_data