Skip to content

Instantly share code, notes, and snippets.

@dbadrian
dbadrian / parse_range.py
Created March 6, 2019 14:32
parse range
def parse_range(astr):
""" Takes a string like "1-3,5,7-9" and returns a list [1,2,3,5,7,8,9] """
result = set()
for part in astr.split(','):
x = part.split('-')
result.update(range(int(x[0]), int(x[-1]) + 1))
return sorted(result)
@dbadrian
dbadrian / effective_modern_cmake.md
Created November 5, 2018 21:26 — forked from mbinna/effective_modern_cmake.md
Effective Modern CMake

Effective Modern CMake

Getting Started

For a brief user-level introduction to CMake, watch C++ Weekly, Episode 78, Intro to CMake by Jason Turner. LLVM’s CMake Primer provides a good high-level introduction to the CMake syntax. Go read it now.

After that, watch Mathieu Ropert’s CppCon 2017 talk Using Modern CMake Patterns to Enforce a Good Modular Design (slides). It provides a thorough explanation of what modern CMake is and why it is so much better than “old school” CMake. The modular design ideas in this talk are based on the book [Large-Scale C++ Software Design](https://www.amazon.de/Large-Scale-Soft

@dbadrian
dbadrian / compile_meshlab.sh
Last active August 9, 2019 15:26
Compile Meshlab on Ubuntu 18.04
#!/bin/bash
#install qt5.9
sudo apt-get install qt5-default qtcreator libqt5xmlpatterns5-dev qtscript5-dev
# install some dependencies
sudo apt-get install libeigen3-dev
#clone repos
git clone --depth 1 https://github.com/cnr-isti-vclab/meshlab.git
@dbadrian
dbadrian / mr_hits.py
Created November 24, 2017 11:49 — forked from bxshi/mr_hits.py
Calculate MeanRank and Hits@K using TensorFlow. From github.com/nddsg/ProjC (private repo right now)
def create_eval_ops(model_input, pred_y, all_triples, eval_triples, n_entity,
top_k, idx_1=0, idx_2=1, idx_3=2):
""" Evaluation operations for any model.
For given <h,r> predict t, idx_1 = 0, idx_2 = 1, idx_3 = 2
For given <t,r> predict h, idx_1 = 2, idx_2 = 1, idx_3 = 0
:param model_input: N by 3 matrix, each row is a h,r,t pair
:param pred_y: N by ENTITY_VOCAB matrix
:param all_triples: M by 3 matrix, contains all triples in the KG
# https://stackoverflow.com/a/33288373
import contextlib
import os
import shutil
import tempfile
@contextlib.contextmanager
def cd(newdir, cleanup=lambda: True):
prevdir = os.getcwd()
os.chdir(os.path.expanduser(newdir))
kill $(ps aux | grep '[p]ython csp_build.py' | awk '{print $2}')
@dbadrian
dbadrian / gist:79f84509b8582fef62bbdd63813cd7cf
Created October 19, 2017 21:40
generate biblatex from zotero via webapi using curl
curl https://api.zotero.org/users/USER_ID/collections/COLLECTIONS_ID/items\?format\=biblatex\&key\=YOURKEY\&v\=3 > output.bib
@dbadrian
dbadrian / aaai_script.sh
Created October 19, 2017 13:36 — forked from chfritz/aaai_script.sh
This shell script produces the latex source-package of a paper as required by AAAI, in preparation for printed proceedings.
#!/bin/bash
# ----------------------------------------------------------------------
# This shell script produces the latex source-package of a paper
# as required by AAAI, in preparation for printed proceedings.
# Copyright (C) 2009 Christian Fritz "fritz at cs dot toronto dot
# edu"
#
# I thank Jorge Baier for his contributions and Shirin Sohrabi for her
# feedback that has lead to improvements to the script. Thanks also
@dbadrian
dbadrian / pacaur_install.sh
Last active March 18, 2017 18:31 — forked from tadly/pacaur_install.sh
A simple shell script to quickly / easily install "pacaur" on archlinux
#!/bin/sh
# If you are new to arch, I encourage you to at least read and understand what
# this script does befor blindley running it.
# That's why I didn't make a one-liner out of it so you have an easier time
# reading and understanding it :)
#
# This scripts purpose is purly to save you a few seconds on your new installation.
#
# Enjoy your time on an awesome system. Arch FTW!