Skip to content

Instantly share code, notes, and snippets.

View draganHR's full-sized avatar

Dragan Bošnjak draganHR

View GitHub Profile
@draganHR
draganHR / cttcx.py
Created April 15, 2012 09:27
CTTCX - Convert CardioTrainer CSV file to TCX file
"""
CTTCX 1.1
Convert CardioTrainer CSV file to TCX file.
Copyright (c) 2012 Dragan Bosnjak <draganHR@gmail.com>
https://twitter.com/dragan
"""
from optparse import OptionParser
from xml.dom.minidom import Document
import os
import csv
@draganHR
draganHR / GeoCityReader.py
Created July 5, 2013 13:07
Extracting city data from GeoIP city edition binary database.
import os
import math
import pygeoip
class GeoCityReader(pygeoip.GeoIP):
"""
Extract city data from GeoIP database
Example:
reader = GeoCityReader('~/GeoLiteCity.dat', pygeoip.MEMORY_CACHE)
for record in reader.get_cities():
@draganHR
draganHR / generate_res.py
Created October 23, 2013 18:02
Scripts for generating PyQT/PySide ui and resource python code
import os
def main():
os.chdir(os.path.dirname(os.path.dirname(__file__)))
src_path = "resources"
dest_path = "myproject/res"
for filename in os.listdir(src_path):
if not os.path.isfile(os.path.join(src_path, filename)):
@draganHR
draganHR / render.py
Last active December 29, 2015 00:59
Render template by using Django template system.
#!/usr/bin/python
"""
render.py
Render template by using Django template system.
Copyright (c) 2013 Dragan Bosnjak <draganHR@gmail.com>
License: MIT
"""
import argparse
@draganHR
draganHR / storage.py
Last active December 30, 2015 04:58
post-process django static files after collectstatic
from django import template
from django.contrib.staticfiles import storage
from django.core.files.base import ContentFile
__version__ = '1.0.0.4'
class StaticFilesStorage(storage.StaticFilesStorage):
def post_process(self, paths, dry_run=False, **options):
@draganHR
draganHR / random_files.py
Created December 13, 2013 15:20
Generate random files
import time
import os
FILE_COUNT = 50
FILE_SIZE = 1 * 1024 * 1024
PATH = "/tmp/random-files"
TIME = time.time()
os.system("mkdir -p %s" % PATH)
os.system("rm -f %s/*" % PATH)
(function($) {
var $scripts = [];
$.getScriptOnce = function(url, success){
if(url instanceof Array && url.length==1)
{
url = url[0];
}
else if(url instanceof Array)
wait4(-1, 0x7fffab51b46c, WNOHANG, NULL) = 0 <0.000043>
epoll_wait(18, {}, 1, 1000) = 0 <1.001164>
gettimeofday({1393494074, 871692}, NULL) = 0 <0.000043>
lseek(2, 0, SEEK_CUR) = 7411 <0.000043>
gettimeofday({1393494074, 871989}, NULL) = 0 <0.000040>
wait4(-1, 0x7fffab51b46c, WNOHANG, NULL) = 0 <0.000042>
epoll_wait(18, {}, 1, 1000) = 0 <1.001161>
gettimeofday({1393494075, 873583}, NULL) = 0 <0.000172>
lseek(2, 0, SEEK_CUR) = 7411 <0.000059>
gettimeofday({1393494075, 874026}, NULL) = 0 <0.000044>
@draganHR
draganHR / build-requirements.sh
Created March 10, 2014 13:25
Build RPM packages from requirements.txt
#!/bin/sh
# Makre sure you installed rpm-build
BASEDIR=$(pwd)
REQUIREMENTS=requirements
mkdir -p requirements-source
mkdir -p requirements-rpms
rm -rf requirements-source/*
import json
import simplejson
import timeit
data = {
"firstName": "John",
"lastName": "Smith",
"age": 25,
"address": {
"streetAddress": "21 2nd Street",