Skip to content

Instantly share code, notes, and snippets.

Avatar

James Shaw hertzsprung

View GitHub Profile
@hertzsprung
hertzsprung / AssertJExceptionsTest.java
Created Apr 12, 2022
AssertJ exception handling alternatives
View AssertJExceptionsTest.java
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();
View destroy-awscdk.sh
# https://github.com/aws/aws-cdk/issues/986#issuecomment-644602463
cdk destroy
aws s3 rm --recursive s3://$(aws s3 ls | grep cdktoolkit | cut -d' ' -f3)
aws cloudformation delete-stack --stack-name CDKToolkit
@hertzsprung
hertzsprung / install-awscli.sh
Last active Apr 26, 2021
Install AWS CLI v2 without sudo
View install-awscli.sh
# download and install to $HOME/bin
# https://docs.aws.amazon.com/cli/latest/userguide/install-cliv2-linux.html
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip awscliv2.zip
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
# https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-completion.html#cli-command-completion-configure
@hertzsprung
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
hertzsprung / doubletexture.cu
Last active Feb 26, 2021
CUDA 2D texture object with double values split into hi/lo int channels
View doubletexture.cu
// inspired by https://devtalk.nvidia.com/default/topic/419190/texture-fetching-for-double-precision-floats/
#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 https://stackoverflow.com/a/32241080/150884
#include <chrono>
#include <iostream>
using Clock = std::chrono::high_resolution_clock;
auto t1 = Clock::now();
// do stuff
auto t2 = Clock::now();
@hertzsprung
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
hertzsprung / face-area.py
Last active Jun 21, 2017
Compare d.S and Heron's formula for face area
View face-area.py
#!/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
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"