Skip to content

Instantly share code, notes, and snippets.


James Shaw hertzsprung

View GitHub Profile
hertzsprung /
Created Apr 12, 2022
AssertJ exception handling alternatives
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.assertj.core.api.Assertions.catchThrowableOfType;
import static org.assertj.core.api.InstanceOfAssertFactories.type;
public class AssertJExceptionsTest {
private final Properties properties = new Properties();
cdk destroy
aws s3 rm --recursive s3://$(aws s3 ls | grep cdktoolkit | cut -d' ' -f3)
aws cloudformation delete-stack --stack-name CDKToolkit
hertzsprung /
Last active Apr 26, 2021
Install AWS CLI v2 without sudo
# download and install to $HOME/bin
curl "" -o ""
cd awscliv2 && ./install -i $HOME/aws-cli -b $HOME/bin
# or update an existing installation:
# cd awscliv2 && ./install -i $HOME/aws-cli -b $HOME/bin --update
# enable bash autocompletion
hertzsprung / structexample.c
Last active Apr 1, 2020
C/C++ struct example
View structexample.c
#include "stdio.h"
#include "stdlib.h"
typedef double real;
struct SolverParams
real dt;
real tolh;
real end_time;
hertzsprung /
Last active Feb 26, 2021
CUDA 2D texture object with double values split into hi/lo int channels
// inspired by
#include <cuda.h>
#include <cuda_runtime_api.h>
#include <cstdio>
#define cudaCheckErrors(ans) { gpuAssert((ans), __FILE__, __LINE__); }
inline void gpuAssert(cudaError_t code, const char *file, int line)
if (code != cudaSuccess)
View timer.cpp
// adapted from
#include <chrono>
#include <iostream>
using Clock = std::chrono::high_resolution_clock;
auto t1 = Clock::now();
// do stuff
auto t2 = Clock::now();
hertzsprung / rotation.C
Last active Dec 21, 2017
Quaternion rotation behaves unexpectedly!
View rotation.C
#include "quaternion.H"
#include "transform.H"
int main(int argc, char *argv[])
const quaternion q(rotationTensor(vector(-1, 0, 0), vector(1, 0, 0)));
Info << q.transform(vector(0, 0, 0.5)) << endl;
hertzsprung /
Last active Jun 21, 2017
Compare d.S and Heron's formula for face area
#!/usr/bin/env python3
import math
import numpy as np
import numpy.linalg as la
def herons_area(v1, v2, v3):
a = la.norm(v2 - v1)
b = la.norm(v3 - v2)
c = la.norm(v1 - v3)
p = 0.5*(a+b+c)
hertzsprung / faceVertexFace.C
Created Mar 2, 2017
OpenFOAM application to find faces that share points (vertices) with other faces
View faceVertexFace.C
#include "fvCFD.H"
using namespace fv;
int main(int argc, char *argv[])
# include "setRootCase.H"
# include "createTime.H"
# include "createMesh.H"