Skip to content

Instantly share code, notes, and snippets.

View draganHR's full-sized avatar

Dragan Bošnjak draganHR

View GitHub Profile
import gc
import sys
import operator
def total_size():
return sum(sys.getsizeof(i) for i in gc.get_objects())
def total_count():
@draganHR
draganHR / Makefile-npm-alchemy
Last active June 17, 2016 21:21
Install npm packages and sync them to vagrant shared directory
export INSTALL_PATH := ${HOME}/node-libs.tmp
npm-delete:
rm -rf ${INSTALL_PATH}
rm -rf node_modules
npm-install:
mkdir -p node_modules
mkdir -p ${INSTALL_PATH}
cp package.json ${INSTALL_PATH}/package.json
SELECT COUNT(*) FROM networkevents_networkevent;
count
----------
13773196
(1 row)
Time: 1115.687 ms
@draganHR
draganHR / .bashrc
Last active March 10, 2016 07:21
rbash jail
# .bashrc
enable -n alias
enable -n bg
enable -n bind
enable -n break
enable -n builtin
enable -n caller
enable -n cd
enable -n command
@draganHR
draganHR / override.conf
Created January 29, 2016 09:19
systemd custom login
#!/bin/bash
# /usr/bin/ttyentrypoint
error_exit() {
echo "[ERROR] $1"
exit
}
exec /bin/bash -c 'reset; echo "Do stuff..."; sleep 10;'
#!/usr/bin/env python
"""
Instructions:
- Put this file at ~/.pythonrc.py
- Add `export PYTHONSTARTUP=~/.pythonrc.py` to ~/.bashrc
Source:
@draganHR
draganHR / format-python2.6.md
Created November 26, 2015 09:39
Cheat sheet for "new style" string formatting in Python 2.6.

Cheat sheet for "new style" string formatting in Python 2.6. It is modified version of examples from http://pyformat.info/ Difference is that simplest sytaxt ( '{}'.format('foo') ) does not work in Python 2.6 and you need to specify value index for each value ( '{0}'.format('foo') ).

Format:

'{1} {0}'.format('one', 'two')

Align right:

<?xml version="1.0"?>
<settings>
<console change_refresh="10" refresh="100" rows="25" columns="80" buffer_rows="500" buffer_columns="0" shell="" init_dir="" start_hidden="0" save_size="0" background_text_opacity="255">
<colors background_text_opacity="255">
<color id="0" r="27" g="25" b="24"/>
<color id="1" r="64" g="126" b="231"/>
<color id="2" r="123" g="151" b="38"/>
<color id="3" r="61" g="151" b="184"/>
<color id="4" r="242" g="44" b="64"/>
<color id="5" r="102" g="102" b="234"/>
@draganHR
draganHR / custom
Last active October 27, 2015 10:18
Custom ansible module
#!/usr/bin/python
# -*- coding: utf-8 -*-
DOCUMENTATION = '''
version_added: "1.0"
module: custom
short_description: Custom ansible module
description:
- Custom ansible module
- Put into ./library/ dir
@draganHR
draganHR / build.sh
Last active October 26, 2015 08:36
Building protobuf-python v2.5.0 with C++ implementation for Centos 7
# Install build tools
sudo yum -y install epel-release
sudo yum -y install rpm-devel rpm-build rpmdevtools python-setuptools python-devel
sudo yum -y install mock
sudo yum -y install fedora-packager
# Install build dependencies
sudo yum install automake libtool emacs emacs-el java-devel jpackage-utils maven-local maven-compiler-plugin maven-install-plugin maven-jar-plugin maven-javadoc-plugin maven-resources-plugin maven-surefire-plugin maven-antrun-plugin