Skip to content

Instantly share code, notes, and snippets.

@hertzsprung
hertzsprung / AssertJExceptionsTest.java
Created April 12, 2022 12:32
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();
@hertzsprung
hertzsprung / destroy-awscdk.sh
Last active November 3, 2020 13:45
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 November 12, 2024 18:15
Install AWS CLI v2 without sudo
# 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 April 1, 2020 13:43
C/C++ struct example
#include "stdio.h"
#include "stdlib.h"
typedef double real;
struct SolverParams
{
real dt;
real tolh;
real end_time;
@hertzsprung
hertzsprung / doubletexture.cu
Last active February 26, 2021 15:30
CUDA 2D texture object with double values split into hi/lo int channels
// 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)
{
@hertzsprung
hertzsprung / timer.cpp
Last active September 10, 2019 13:43
C++ timers
// 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 December 21, 2017 11:34
Quaternion rotation behaves unexpectedly!
#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 June 21, 2017 13:18
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
hertzsprung / faceVertexFace.C
Created March 2, 2017 16:22
OpenFOAM application to find faces that share points (vertices) with other faces
#include "fvCFD.H"
using namespace fv;
int main(int argc, char *argv[])
{
# include "setRootCase.H"
# include "createTime.H"
# include "createMesh.H"