Skip to content

Instantly share code, notes, and snippets.

View csullivan's full-sized avatar

Chris Sullivan csullivan

  • OctoML
  • Portland
View GitHub Profile
py.python_import("pylab","plot");
py.python_import("pylab","savefig");
vector<float> rand;
py.__py("import numpy as np; import pylab");
// create an arbitrary list in python and extra
@csullivan
csullivan / gist:e567f0ad9b411bfd1b59
Last active November 17, 2015 19:32
Run-Time Type Information (RTTI) check with dynamic_cast
auto thing = dynamic_cast<derived_type*>(object->GetBaseObject());
if(thing!=nullptr) {
thing->MethodOfDerivedClass();
}
@csullivan
csullivan / iowidth
Created January 7, 2016 15:07
iostream width and fill (leading zeros)
Set width of integer output:
#include <iostream>
#include <iomanip>
int main() {
cout << setfill('0') << setw(2) << 5 << endl;
return 0;
}
@csullivan
csullivan / reference_member.cc
Created January 21, 2016 00:34
A snippet detailing how a class may have a reference member
#include <iostream>
using namespace std;
class B {
public:
B() {x = 0;}
~B() {;}
int x;
@csullivan
csullivan / simple_template.pbs
Created February 22, 2016 19:43
A cluster submission file template for use with torque/pbs
#!/bin/sh
### name of job
#PBS -N JOB_NAME
### email on _a_bort, _b_egin, _e_nd
#PBS -m abe
### combine stdout/stderr
#PBS -j oe
### resource requests (time in HH:MM:SS)
#PBS -l walltime=99:00:00
### dont retry
@csullivan
csullivan / ANL_raw.cc
Created February 28, 2016 21:30
GEB Digitizer Notes (ANL vs LBL)
In the ANL data format, I observe that the hexidecimal divider 0xaaaaaaaa does not appear in the raw data format.
e.g.
ANL:
00000000: 0e00 0000 4000 0000 9c21 e6cc 8301 0000 ....@....!......
00000010: 1810 0711 cce6 219c 7001 0183 99c9 0000 ......!.p.......
00000020: 0181 f385 0080 398e 0000 0000 c42b d4da ......9......+..
00000030: 0000 2be6 0000 0000 2007 2019 200c 2023 ..+..... . . . #
00000040: 200e 0000 2003 2005 1ff9 1ff9 1fed 1ff6 ... . .........
@csullivan
csullivan / calcq.py
Created April 19, 2016 19:59
Script to calculate nuclear Q-values from AME2012 (Atomic Mass Evaluation) data.
import numpy as np
def get_ame_masses(path):
masses = np.zeros((400,400))
for line in open(path):
@csullivan
csullivan / example_virtual.cpp
Created May 11, 2016 20:23
Illustrating the difference between virtual function overrides and non-virtual derived class methods with the same name and function signature
#include <iostream>
using namespace std;
class Base {
public:
Base(){;}
virtual ~Base(){;}
void Func() {
cout << "Base::Func" << endl;
@csullivan
csullivan / constraint_template_example.cc
Last active July 28, 2016 16:04
An example using c++ constraints and concept templates
// Function template constraint (implicit or "ad-hoc")
template<typename T> requires
requires (T a) { a + a; } &&
requires (T b) { b * b; } &&
requires (T c) { sqrt(c); }
T Magnitude(vector<T>&& vec) {
T sum;
for (auto& const i : vec) { sum += i*i; }
return sqrt(sum);
S - Set of all nodes with no inbound connections (NodeType::Input)
-- Enumerating all paths
paths = {}
for each node n in S do
visit(n,{})
function visit(node n, list l)
if n is not in l then