Skip to content

Instantly share code, notes, and snippets.

View mikeando's full-sized avatar

Mike Anderson mikeando

  • DownUnder GeoSolutions
  • Perth
View GitHub Profile
@mikeando
mikeando / Demo.c
Last active March 20, 2024 10:47
Example of using C++ from C.
#include "HMyClass.h"
#include <stdio.h>
void my_eh( const char * error_message, void * unused)
{
printf("my_eh: %s\n", error_message);
}
int main()
{
@mikeando
mikeando / thiserror_backtrace.rs
Created May 12, 2020 23:51
Example of backtrace usage in thiserror
#![feature(backtrace)]
extern crate thiserror;
use thiserror::Error;
use std::backtrace::Backtrace;
#[derive(Error, Debug)]
pub enum DataStoreError {
//#[error("data store disconnected")]
@mikeando
mikeando / README.md
Last active February 4, 2023 01:02
Fraction approximation in C++
pub struct CircularQueue<T> {
queue: Vec<Option<T>>,
head: usize,
tail: usize,
max_capacity: usize,
count: usize,
}
impl<T> CircularQueue<T> {
pub fn new(size: usize) -> CircularQueue<T> {
@mikeando
mikeando / README.md
Last active December 18, 2019 08:34
Output buffer as binary, similar to xxd in java

Simple XXD Style output from a ByteBuffer.

Refactored here without testing, so probably no-longer compiles - but should be a good starting point should I need it again.

@mikeando
mikeando / demo.py
Last active November 15, 2019 07:57
Devito comm mismatch
import numpy as np
from dugwave.devitowrap import Function, TimeFunction, Grid, Eq, Operator, configuration, Constant, SpaceDimension, SubDimension, solve
from sympy import Symbol
from mpi4py import MPI
bc_thickness = 4
nx=10
ny=10
dx=0.1
@mikeando
mikeando / mpi_heat_test.py
Created November 8, 2019 07:24
Example bad devito MPI operator
import numpy as np
import cloudpickle
from mpi4py import MPI
from devito import Function, TimeFunction, Grid, Eq, Operator, configuration
configuration["mpi"] = True
configuration["openmp"] = True
@mikeando
mikeando / fast_sin.cpp
Created May 24, 2011 10:03
fast sine approximations
#include <math.h>
#include <stdio.h>
// P Found using maxima
//
// y(x) := 4 * x * (%pi-x) / (%pi^2) ;
// z(x) := (1-p)*y(x) + p * y(x)^2;
// e(x) := z(x) - sin(x);
// solve( diff( integrate( e(x)^2, x, 0, %pi/2 ), p ) = 0, p ),numer;
//
#include <cerrno>
#include <iostream>
#include <typeinfo>
//Here's a simple function that does exactly what we might expect
void testx( int * errnox ) {
std::cout<<"in testx type of errno = "<<typeid(errnox).name() <<std::endl;
if(errnox) {
*errnox = 7;
std::cout<<"errnox is "<<errnox<<std::endl;
@mikeando
mikeando / Makefile
Created June 24, 2011 02:36
Example for failing compile on system symbol usage
all: should_work.x should_fail.x
should_fail.x : should_fail.o fncheck.o
gcc should_fail.o fncheck.o -Xlinker -dead_strip -o should_fail.x
should_work.x : should_work.o fncheck.o
gcc should_work.o fncheck.o -Xlinker -dead_strip -o should_work.x
should_fail.o : should_fail.c
gcc -c should_fail.c