Skip to content

Instantly share code, notes, and snippets.

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

Jan Pipek janpipek

🤔
...
View GitHub Profile
@janpipek
janpipek / c_cpp_properties.json
Created October 3, 2017 10:02
VS C++ settings
{
"configurations": [
{
"name": "null",
"includePath": [
"/usr/include/c++/7/", "/usr/include/c++/7/tr1", "/usr/include/linux",
"/usr/include/c++/7/x86_64-redhat-linux",
"~/opt/geant4.10.04.b01/include/Geant4", "${workspaceRoot}/include",
"${workspaceRoot}/lib", "/usr/include/qt5","/usr/include/qt5/QtWidgets","/usr/include/qt5/QtGui",
"/usr/include/qt5/QtCore", "/usr/lib64/qt5/./mkspecs/linux-g++", "/usr/include/qt5/QtPrintSupport", "/usr/include/qt5/QtOpenGL"
@janpipek
janpipek / munro.py
Created March 16, 2017 13:01
Convert a certain Munro table into more digestible
import pandas as pd
munros = pd.read_csv("../physt/example/munrotab_v6.csv", encoding="latin-1")
munros = munros[munros["Post 1997"] == "MUN"]
munros["name"] = munros["Name"]
munros["height"] = munros["Height (m)"]
from bng_to_latlon import OSGB36toWGS84
munros["lat"], munros["long"] = tuple(zip(*[OSGB36toWGS84(*pair) for pair in (zip(munros.xcoord, munros.ycoord))]))
munros = munros[["name", "height", "long", "lat"]].reset_index(drop=True)
@janpipek
janpipek / head_n_tail.py
Created March 2, 2017 16:13
Functional head & tail in Python
from itertools import islice
from toolz.itertoolz import sliding_window, last
import codecs
import os
def head(path, n=10, encoding="utf-8"):
with codecs.open(os.path.expanduser(path), encoding=encoding) as f:
yield from map(lambda x: x.rstrip(), islice(f, n))
def tail(path, n=10, encoding="utf-8"):
@janpipek
janpipek / qwebkit_mathjax.py
Last active November 10, 2016 10:59
SImplest Qt + Webkit + MathJax
from PyQt4 import QtCore, QtGui, QtWebKit
import sys
app = QtGui.QApplication(sys.argv)
# Define content
head = """
<script type="text/x-mathjax-config">MathJax.Hub.Config({tex2jax: {inlineMath: [['$','$']]}});</script>
<script type="text/javascript" async src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_CHTML"></script>"""
body = "$x + 4$"
@janpipek
janpipek / elements.py
Created September 24, 2016 16:57
Transform element numbers into symbols
from collections import OrderedDict
elements = OrderedDict([(1, 'H'),
(2, 'He'),
(3, 'Li'),
(4, 'Be'),
(5, 'B'),
(6, 'C'),
(7, 'N'),
(8, 'O'),
@janpipek
janpipek / rename_numbered.py
Created September 5, 2016 05:50
Rename numbered file names to padded variant
import os
import math
def rename(basename, basename2=None, extension=None, directory="."):
"""Rename all XXX1.ext, XXX123.ext files to XXX001.ext, ..."""
if basename2 is None:
basename2 = basename
files = [name for name in os.listdir(directory) if name.startswith(basename)]
if extension:
files = [name for name in files if name.endswith(extension)]
@janpipek
janpipek / multiply_rows
Last active August 3, 2016 14:25
Make multiple copies of each row
import numpy as np
def multiply_rows(df, n, group=True):
"""Make multiple copies of each row in pandas.
:param df: the dataframe
:param n: how many copies
:param group: whether to group copies next to each other (AABB) or not (ABAB)
"""
new_df = pd.DataFrame()
@janpipek
janpipek / cnb.py
Last active March 1, 2016 19:00
ČNB (Czech National Bank) exchange rates with python and pandas.
def read_cnb_year(year):
"""Read the whole history of Czech National Bank rates in one year.
:param year: 1991-2016 (or "today's year")
"""
import urllib.request
from io import StringIO
import pandas as pd
url = "https://www.cnb.cz/cs/financni_trhy/devizovy_trh/kurzy_devizoveho_trhu/rok.txt?rok={0}".format(year)
@janpipek
janpipek / install-geant4.sh
Last active February 15, 2016 11:00
Installation of Geant4
#!/usr/bin/bash
# module load cmake/3.4.3
export SW_NAME=geant4
export PACKAGE_VERSION=10.02
export PACKAGE_NAME=$SW_NAME.$PACKAGE_VERSION
export PACKAGE_DIR=$HOME/install/packages
export PACKAGE_FILE=$PACKAGE_DIR/$PACKAGE_NAME.tar.gz
export URL=http://geant4.cern.ch/support/source/$PACKAGE_NAME.tar.gz
@janpipek
janpipek / 0-ElimedConventions.md
Last active January 10, 2016 17:32
Elimed C++ conventions.

These two files contain my idea of proper C++ coding conventions. Please feel free to comment below (and I can update).