Skip to content

Instantly share code, notes, and snippets.

View janpipek's full-sized avatar
🤔
...

Jan Pipek janpipek

🤔
...
View GitHub Profile
@janpipek
janpipek / Geant4InterfaceOptions.cmake
Last active December 9, 2015 12:17
Alternative CMake for Geant4 that enables forcing of Qt version
# - Configure options for Geant4 UI/Vis requiring Third Party Libraries
# All core Interfaces not requiring third party support are built
# automatically with platform differences taken into account.
# These are:
#
# UI Category : Always built on supported platforms
# G4UIterminal : UNIX, WIN32
# + - G4UItcsh : UNIX only.
# + - G4UIcsh : UNIX, WIN32
# G4UIWin32 : WIN32
@janpipek
janpipek / fix-geant4.10.1.2-qt5.patch
Last active October 7, 2015 15:17
FIx to use Qt5 with Geant4 10.1.p02
diff -rup geant4.10.01.p02-p/source/interfaces/basic/src/G4UIQt.cc geant4.10.01.p02/source/interfaces/basic/src/G4UIQt.cc
--- geant4.10.01.p02-p/source/interfaces/basic/src/G4UIQt.cc 2015-03-16 16:55:41.000000000 +0100
+++ geant4.10.01.p02/source/interfaces/basic/src/G4UIQt.cc 2015-10-07 15:52:15.182301156 +0200
@@ -721,7 +721,7 @@ bool G4UIQt::AddTabWidget(
fViewerTabWidget->addTab(aWidget,name);
- fViewerTabWidget->setCurrentIndex(fViewerTabWidget->count()-1);
+// fViewerTabWidget->setCurrentIndex(fViewerTabWidget->count()-1);
@janpipek
janpipek / csv2hdf.py
Created September 22, 2015 14:28
Convert CSV files to HDF5 format
#!/usr/bin/env python
import pandas as pd
import sys
def convert(source_name, target_name, dataset_name=None, group_name=None):
# data_set_name & group_name not yet used
if not group_name:
dataset_name = ".".join(s for s in source_name.split(".") if s not in ("csv", "gz", "dat", "txt", "tsv"))
# print(group_name)
@janpipek
janpipek / init_qtcreator_geant4.py
Created September 14, 2015 14:41
How to properly initialize includes file for Geant4 sources
import os
with open("Geant4.10.p01.includes", "w") as f:
for d in os.walk("."):
if len(d[0]) > 0:
f.write(d[0][2:] + "\n")
@janpipek
janpipek / unzip_with_encoding.py
Created June 17, 2015 06:20
Unzip ZIP packages with non-ASCII encoding on Linux
#!/usr/bin/env python
import os
import zipfile
import sys
def unzip_with_encoding(archive_path, output_path, encoding):
zz = zipfile.ZipFile(archive_path)
for fp in zz.filelist:
bytes = zz.read(fp.filename)
@janpipek
janpipek / pycharm_load_entry_point.py
Created June 10, 2015 12:50
Hack Pycharm to start IPython 3.1
# This file should replace ${CHARM_DIR}/helpers/pycharm/pycharm_load_entry_point.py
import os, sys
from pkg_resources import load_entry_point
if __name__ == '__main__':
dist = os.environ.get("PYCHARM_EP_DIST")
name = os.environ.get("PYCHARM_EP_NAME")
if dist == "ipython" and name == "ipython":
from IPython import start_ipython
@janpipek
janpipek / export_from_instiki
Created May 3, 2015 06:17
Export documents from old instiki database
def export_from_instiki(file_name, output_dir, extension="md"):
"""Export data from instiki database to external files."""
import sqlite3
import os
import codecs
db = sqlite3.connect(file_name)
cur = db.execute("SELECT * from pages")
if not os.path.exists(output_dir):
os.makedirs(output_dir)
while True:
@janpipek
janpipek / locale_sort_win.py
Created April 22, 2015 18:55
sort using locale in windows (>= Vista???)
import ctypes
from ctypes import windll
kernel32 = windll.LoadLibrary("kernel32")
import functools
def compare(str1, str2, locale="cs-CZ"):
res = kernel32.CompareStringEx(
ctypes.c_wchar_p(locale),
ctypes.c_ulong(0),
ctypes.c_wchar_p(str1),
@janpipek
janpipek / tree.py
Last active August 29, 2015 14:18
Quick HTML tree of file structure
# -*- coding: utf-8 -*-
import os
import sys
from collections import OrderedDict
begin = u"""<!DOCTYPE html>
<html><head><meta charset="UTF-8"></head><style>li {
list-style: none;
}
@janpipek
janpipek / HttpRequest.hh
Last active August 29, 2015 14:18
Simple C++ wrapper around libcurl HTTP GET
#include <curl/curl.h>
#include <string>
class HttpRequest {
public:
HttpRequest(const std::string& url) : _url(url) { }
const std::string getResponse() {
doIt();
return _buffer;