Skip to content

Instantly share code, notes, and snippets.

View dvalters's full-sized avatar

Declan Valters dvalters

View GitHub Profile
@dvalters
dvalters / tell_me_the_type.cpp
Created December 3, 2018 09:56
Get the type of a variable (C++17)
// This file is a "Hello, world!" in C++ language by GCC for wandbox.
#include <iostream>
#include <cstdlib>
// https://stackoverflow.com/questions/81870/is-it-possible-to-print-a-variables-type-in-standard-c
template <class T>
constexpr
std::string_view
type_name()
@dvalters
dvalters / WhatIsStrictAliasingAndWhyDoWeCare.md
Created September 14, 2018 16:04 — forked from shafik/WhatIsStrictAliasingAndWhyDoWeCare.md
What is Strict Aliasing and Why do we Care?

What is the Strict Aliasing Rule and Why do we care?

(OR Type Punning, Undefined Behavior and Alignment, Oh My!)

What is strict aliasing? First we will describe what is aliasing and then we can learn what being strict about it means.

In C and C++ aliasing has to do with what expression types we are allowed to access stored values through. In both C and C++ the standard specifies which expression types are allowed to alias which types. The compiler and optimizer are allowed to assume we follow the aliasing rules strictly, hence the term strict aliasing rule. If we attempt to access a value using a type not allowed it is classified as undefined behavior(UB). Once we have undefined behavior all bets are off, the results of our program are no longer reliable.

Unfortunately with strict aliasing violations, we will often obtain the results we expect, leaving the possibility the a future version of a compiler with a new optimization will break code we th

import subprocess
import matplotlib.pyplot as plt
import numpy as np
def generate_plot_figures():
NUM_PLOTS_TO_ANIMATE = 10
for i in range(NUM_PLOTS_TO_ANIMATE + 1):
# Create each plot separately
fig, ax = plt.subplots()
@dvalters
dvalters / voxelproblem.py
Last active July 23, 2018 10:25
Mapping the 2D array of burn days to a True/False voxelspace
# Plain for loops
import numpy as np
for j in range(one_month_data.shape[1]):
for i in range(one_month_data.shape[0]):
if not np.isnan(one_month_data[i,j]):
voxelspace[int(one_month_data[i,j]), i, j] = True if one_month_data[i,j] > 0 else False
elif np.isnan(one_month_data[i,j]);
date_start, date_end = get_dates_for_current_month() # return integers
voxelspace[date_start:date_end, i, j] = np.nan
elif one_month_data[i,j] == 0;
@dvalters
dvalters / convert multiple.sh
Created May 14, 2018 06:58
Resize photos bulk with convert
mkdir photos-Optimized;for photos in *.jpg;do convert -verbose $photos -quality 85% -resize 1600x900 ./photos-Optimized/$photos-Optimized.jpg ; done
@dvalters
dvalters / 3d_2d.py
Last active April 22, 2018 12:19
Experiments 3D map Vis. LSDMapping Tools
# Author: S. Chris Colbert <sccolbert@gmail.com>
# Copyright (c) 2009, S. Chris Colbert
# License: BSD Style
from __future__ import print_function
# this import is here because we need to ensure that matplotlib uses the
# wx backend and having regular code outside the main block is PyTaboo.
# It needs to be imported first, so that matplotlib can impose the
# version of Wx it requires.
@dvalters
dvalters / bit_review_JOSS.md
Created February 13, 2018 10:20
# Review of 'bit' (JOSS)

Review of JOSS paper 'bit'

@dvalters
dvalters / disk space.markdown
Last active January 2, 2024 15:53
Disk space usage

Disk space usage

Here are some notes on the various ways to check disk space usage on linux:

Disk usage of all (non-hidden) files and folders

Using the du command (disk use) with the -s (summarize) and -h (human-readable) options.

du -sh *
@dvalters
dvalters / array_split_review.markdown
Last active September 7, 2017 19:15
array_split review

Review summary

My review is quite short as I could find little to fault in the submission. The standard of the array_split software package is high. It is well documented and with a good level of testing. It provides a useful and substantial extension to the functionality of the basic NumPy array splitting functions. There are good applications for scientific parallel codes as the author suggests in the paper. The quality of the Python code is also high.

I have very few requests before the paper can be accepted, just minor issues with some of the references:

References

Could you check that DOIs are provided for papers that have them. The Dalcin (2011) paper has a DOI available on the Science Direct website, but it is not included in the .bib file. Similarly for the reference to scikit-image (https://www.ncbi.nlm.nih.gov/pubmed/25024921), and the NumPy Array reference (http://ieeexplore.ieee.org/document/5725236/).

Once these

@dvalters
dvalters / noeditor.sh
Created August 10, 2017 21:13
Skip the editor, pipe code straight to compiler!
printf "#include <stdio.h> \n int main() { printf( \"Hello, World \\\n\" ); return 0; }" | gcc -x c -