Skip to content

Instantly share code, notes, and snippets.

View mastbaum's full-sized avatar

Andy Mastbaum mastbaum

  • Rutgers University
  • New Brunswick, NJ
View GitHub Profile
@mastbaum
mastbaum / random_deref.cpp
Created June 2, 2011 16:40
An example of buffer overflows in C++ STL vectors
#include<iostream>
#include<vector>
#include<stdlib.h>
/** People sometimes get the false impression that because STL and iterators
* are fairly new additions to C++, they do sensible, commonplace things like
* bounds checking.
*
* This is sadly not the case, since preserving backwards-compatibility with C
* means preserving the loaded-gun-pointed-at-your-foot aspects, too.
@mastbaum
mastbaum / custom_directive.py
Created May 10, 2012 20:32
Example of a custom ReST directive in Python docutils
'''Example of a custom ReST directive in Python docutils'''
import docutils.core
from docutils.nodes import TextElement, Inline
from docutils.parsers.rst import Directive, directives
from docutils.writers.html4css1 import Writer, HTMLTranslator
class foo(Inline, TextElement):
'''This node class is a no-op -- just a fun way to define some parameters.
There are lots of base classes to choose from in `docutils.nodes`.
@mastbaum
mastbaum / nulobster.py
Created May 8, 2015 22:19
Neutrinoless double-beta decay "lobster" plot
'''Make the "lobster plot."
That is, the possible values of the Majorana mass given the mixing parameters
and assuming standard three-neutrino mixing, for the normal and inverted
mass hierarchy.
By the way, the current global best fit parameters from NuFit are:
sin(t12)^2 = 0.304 +/- 0.012
sin(t23)^2 = 0.451 +/- 0.002 (first quadrant)
@mastbaum
mastbaum / ftrapv.cpp
Created June 2, 2011 16:38
A demonstration of GCC's ftrapv flag for C++ integer overflow debugging
#include<iostream>
#include<signal.h>
#include<limits.h>
/** g++'s -ftrapv flag provides some protection against integer overflows. It
* is a little awkward to use, though. All it will do is "trap" -- you must
* provide a signal handler to deal with it.
*
* (You must compile with -ftrapv for this to work)
*/
@mastbaum
mastbaum / slurm.conf
Last active May 17, 2017 12:46
Example slurm.conf for elastic cluster
# Example /etc/slurm-llnl/slurm.conf
ControlMachine=master
ControlAddr=192.168.57.100
Proctracktype=proctrack/linuxproc
SlurmctldPort=6819
SlurmdPort=6818
SlurmdSpoolDir=/tmp/slurmd
SlurmUser=slurm
StateSaveLocation=/tmp/slurmd
SwitchType=switch/none
@mastbaum
mastbaum / startnode
Created November 1, 2015 18:26
Docker SLURM node Resume and Suspend scripts
#!/bin/bash
echo "`date` Resume invoked $0 $*" >> /var/log/slurm-llnl/power_save.log
hosts=`scontrol show hostnames $1`
for host in $hosts
do
docker run --rm \
--name $host \
-h $host \
-v /home:/home \
@mastbaum
mastbaum / TestUser.cc
Created April 11, 2017 19:28
RAT-PAC setup to look at antiprotons
// This lives in user/
///////////////////////////////////////////////////////////////////////////////
/// \file TestUser.cc
/// \brief An example User Processor
///
/// This example demonstrates how to write a User Processor. MyUserProc
/// (declared and defined below) just creates a 1-D histogram of the number of
/// photoelectrons in each event, filled it as events are generated and writes
/// it to a file called "numpe.root".
@mastbaum
mastbaum / check_couchdb_replications.py
Last active December 8, 2016 20:05
Nagios plugin to check that CouchDB replications are working
#!/usr/bin/env python
'''Check to make sure that all the replications on the local CouchDB server
are actually running.'''
import argparse
from datetime import datetime, timedelta
from operator import itemgetter
import requests
import sys
import tempfile
@mastbaum
mastbaum / check_smart_status.py
Created April 14, 2014 16:39
Nagios SMART status check
#!/usr/bin/env python
'''Report the SMART status of hard disks using a log file.'''
import argparse
import subprocess
import sys
# Nagios status codes
OK, WARNING, CRITICAL, UNKNOWN = range(4)
@mastbaum
mastbaum / install-build-couchdb.sh
Created December 1, 2014 19:13
CouchDB 1.6.1 on CentOS 6.6 with build-couchdb
#!/bin/bash
git clone git://github.com/jhs/build-couchdb.git
cd build-couchdb
git submodule init
git submodule update
rake erl_checkout="OTP_R15B03-1" git="git://git.apache.org/couchdb.git 1.6.1" install=/opt/build-couchdb-dependencies couchdb_build=/opt/couchdb/1.6.1