Skip to content

Instantly share code, notes, and snippets.


Dario Berzano dberzano

View GitHub Profile
#!/usr/bin/env python
"""Generate a LaTeX longtable automatically spanning on multiple pages with images proportionally
scaled appropriately. Adds a scale ruler too. Image names must have a certain format.
from __future__ import print_function
import sys
import os.path
import re
from __future__ import print_function
def disaster_function(a_default=[]):
# BEWARE: the next line, if a_default is not provided, modifies the default
# object, and **not a copy** of the default object! This is because you are
# modifying in place a "name" pointing to the default, by effectively changing
# the default value for all future function calls
a_default.append("a string")
print("disaster_function(): %s" % a_default)
dberzano /
Last active Mar 7, 2017
Python decorators for class members
#!/usr/bin/env python
# Will print:
# init method
# decorator here
# called with a message
# 12345
# modern decorator here with decorator with a message
# yabba with another message
# 54321
dberzano /
Created Nov 11, 2015
CPU efficiency on Linux with Python
#!/usr/bin/env python
from time import sleep
ncpus = sum([ 1 for x in open("/proc/cpuinfo").read().split("\n") if "bogomips" in x ])
def getup():
tot,idle = open("/proc/uptime").read().split(" ")
return float(tot)*ncpus,float(idle)
dberzano /
Created Jan 30, 2015
Get CernVM Online context from API
#!/usr/bin/env python
# Usage:
# [--user-data] <context_id> [<context_key>]
import sys
import requests
import base64
import hashlib
from Crypto.Cipher import AES
dberzano / CMakeLists.txt
Created Jan 28, 2015
CMake: how to use optional arguments in macros and how to escape/unescape args to a shell
View CMakeLists.txt
cmake_minimum_required(VERSION 2.8)
macro(testmacro testarg1 testarg2)
message(STATUS "testarg1 = \"${testarg1}\"")
message(STATUS "testarg2 = \"${testarg2}\"")
message(STATUS "Optional arg = \"${ARGV2}\"")
dberzano / ShowRootMaps.C
Created Jan 27, 2015
Show current rootmaps in ROOT
View ShowRootMaps.C
void ShowRootMaps() {
TObjArray *oa = gInterpreter->GetRootMapFiles();
TIter i(oa);
TObject *o;
TNamed *n;
TString s;
while ((o = i.Next()) != NULL) {
n = dynamic_cast<TNamed *>(o);
Printf("%-40s --> %s", n->GetName(), n->GetTitle());
dberzano / condor_job_memory
Created Oct 23, 2014
HTCondor: define memory policies
View condor_job_memory
## Pretend that all jobs have very low memory requirements: useful
## when running pilot jobs (e.g. AliEn)
dberzano /
Created Jul 21, 2014
Patch MTU on KVM uCernVM image
cd $(dirname "$0")
[ ! -e ${ucvm}.orig ] && cp $ucvm ${ucvm}.orig
t=$(mktemp -d /tmp/cvm-initrd-XXXXX)
cd $t
echo starting guestfish
eval "`guestfish --listen`" || exit 1
echo mounting fs
guestfish --remote add $ucvm : run : mount /dev/sda1 / || exit 1
dberzano / condor_user_quotas
Last active Aug 29, 2015
HTCondor: per-user "quotas" using match making
View condor_user_quotas
# "Quotas" per user
# Our requirements contain an expression that changes at every accepted job. We
# cannot therefore optimize matchmaking by caching the results for a specific
# "requirements" string, but we will need to evaluate it per job.
# The following two variables are set to enforce these "quotas" on setups with