Skip to content

Instantly share code, notes, and snippets.

View draganHR's full-sized avatar

Dragan Bošnjak draganHR

View GitHub Profile
@draganHR
draganHR / curl-loop.sh
Last active August 29, 2015 14:05
Usage: curl-loop.sh <url> <count>
#!/bin/bash
URL=$1
COUNT=$2
if [ -z "${COUNT}" ]; then
COUNT=10
fi
echo "Downloading ${URL}:"
@draganHR
draganHR / genlrf.sh
Created October 1, 2014 09:56
Generate large random files
FNAME=$1
COUNT=$2
i=1
while [[ $i -le $COUNT ]]
do
echo "$i..."
openssl rand -out out-${FNAME}.${i}.bin -base64 $(( 2**30 * 3/4 ))
((i = i + 1))
done
@draganHR
draganHR / django_command_multiprocessing_example.py
Last active August 5, 2020 17:40
Example of django command using multiprocessing
import logging
from time import sleep
from multiprocessing import Process
from django.core.management.base import BaseCommand, CommandError
logger = logging.getLogger(__name__)
@draganHR
draganHR / elasticsearchserver_plugin.py
Created November 9, 2014 09:55
Run test elasticsearch server
from elasticsearch import Elasticsearch, TransportError
from nose.plugins import Plugin
import os
import shutil
import subprocess
import tempfile
import socket
from time import sleep
@draganHR
draganHR / looper.py
Created March 24, 2015 10:39
periodic python scheduler
import sched, time
class looper(sched.scheduler):
def loop(self, interval, p, action, actionargs=()):
self.enter(interval, 1, self.loop, (interval, p, action, actionargs))
action(*actionargs)
s = looper(time.time, time.sleep)
@draganHR
draganHR / generate_images.py
Last active August 29, 2015 14:21
generate_images.py
from itertools import cycle
import sys
import argparse
import random
from PIL import ImageFont
from PIL import Image
from PIL import ImageDraw
import datetime
INFO 2015-06-12 09:39:01,562 77120 139952186169088 samples.collector Collector 0969b32ef602cfffb1a6b48f433abaf182f855e1 starting
ERROR 2015-06-12 09:39:01,587 77120 139952186169088 samples.management.commands.collector_agent Message processing failed
Traceback (most recent call last):
File "/opt/tcbase/tcbase/samples/management/commands/collector_agent.py", line 77, in handle_message
result = obj.process(data)
File "/usr/lib/python2.6/site-packages/django/db/transaction.py", line 371, in inner
return func(*args, **kwargs)
File "/opt/tcbase/tcbase/samples/collector.py", line 133, in process
self.process_samples(data, tool, source, root_sample)
File "/opt/tcbase/tcbase/networkevents/collector.py", line 125, in process_samples
class A(object):
def method(self):
print "I'm method in A"
def __method__(self):
print "I'm __method__ in A"
def __method(self):
print "I'm __method in A"
@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
@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