Skip to content

Instantly share code, notes, and snippets.

View kotnik's full-sized avatar

Nikola Kotur kotnik

View GitHub Profile
@kotnik
kotnik / fabfile.py
Created July 19, 2013 13:40 — forked from joshkehn/fabfile.py
Update all packages with Fabric calling pip.
from fabric.api import local
import pip
def freeze ():
local("pip freeze > requirements.txt")
local("git add requirements.txt")
local("git commit -v")
def upgrade ():
for dist in pip.get_installed_distributions():
@kotnik
kotnik / gist:6191642
Created August 9, 2013 06:48
Simple sample Vagrantfile.
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
# Every Vagrant virtual environment requires a box to build off of.
config.vm.box = "precise64"
# The url from where the 'config.vm.box' box will be fetched if it
# doesn't already exist on the user's system.
config.vm.box_url = "http://files.vagrantup.com/precise64.box"
@kotnik
kotnik / gist:6204246
Created August 11, 2013 09:55
Honeypot trap to add in *_form_alter (Drupal 7).
// Add Honeypot protection.
if (module_exists('honeypot')) {
honeypot_add_form_protection($form, $form_state, array('honeypot', 'time_restriction'));
}
@kotnik
kotnik / gist:6561982
Last active December 23, 2015 01:39
Validate schema with Colander for either uuid or mail are in the request.
@deferred
def deferred_check_missing(node, kw):
try:
json_request = kw.get("request").json_body
except ValueError:
raise Invalid(node, "Malformed JSON provided")
if "mail" not in json_request and "uuid" not in json_request:
raise Invalid(node, "Both mail and uuid are missing")
@kotnik
kotnik / gist:6569574
Created September 15, 2013 10:36
Proper way to consistently read `/proc/mounts`.
import re
import collections
def get_current_mounts():
""" Get the currently mounted filesystems. """
# Reading from /proc/mounts is only consistent within a single read(3)
# call. Unfortunately, the maximum amount of data you can get from
# this file in a single call is hardcoded by the kernel to PAGE_SIZE
# (4096 bytes on x86). As a consequence, there is no way to read
ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAQEAvzMU1f2mRAMTSSJmLp3QFfnZIk4AGlZQggSO1OuMEn9sqvmHSEyckW516A4eoqBvukFod4bBjl72bNZBMSCXjgELmiGxNvr0iDeuefSR4vHKBqgUp9HhDakSNGz6eBjV5XN0iyhzwe/0N4PHq0wlwwETAE1QzHGia9RiIfpo6jYUPehzUi7CKXJLmmtaOTRm6zRNdrj1P97ZBw/5CbPT2yOYPQlnl1A/FQqxocODKTSCGQSvrOZ1Y0qCmg0Fl63PcpH2KDZW5FIcIA8yPWE07xT7zfQOe+wu3IZ+aK38hUGdoZmzYPlGo49vf03/KOo6vwBUzeY2SEbZ/Nflu+F80Q==
@kotnik
kotnik / gist:7908359
Created December 11, 2013 10:44
Clean up after testing the DRBD
eval $(ls /dev/drbd* | sed 's/\/dev\/drbd//g' | awk '{print "drbdsetup " $1 " down;"}' ) ; lvremove -f /dev/platform_test/*-0 ; lvremove -f /dev/platform_test/*-1
@kotnik
kotnik / gist:9131458
Created February 21, 2014 09:43
Wipe the squid away
systemctl stop squid.service
rm -rf /var/spool/squid
mkdir -p /var/spool/squid
chown proxy: /var/spool/squid
squid -z
systemctl start squid.service
@kotnik
kotnik / project.make
Last active August 29, 2015 13:57 — forked from perusio/project.make
; -*-conf-*-
api = 2
core = 7.x
; Commerce kickstart.
projects[commerce_kickstart][type] = core
; Be2Bill needed modules.
projects[commerce_cardonfile] = "2.0-beta2"
projects[commerce_be2bill] = "1.x-dev"
@kotnik
kotnik / print_pkg_deps.py
Created May 7, 2014 07:48 — forked from mtayseer/print_pkg_deps.py
Print a list of installed packages and their dependencies
import pkg_resources
for pkg in pkg_resources.working_set:
if pkg.requires():
print '{} => {}'.format(pkg.key, ', '.join(req.project_name for req in pkg.requires()))
else:
print pkg.key