Skip to content

Instantly share code, notes, and snippets.

View multiplemonomials's full-sized avatar

Jamie Smith multiplemonomials

  • USC Rocket Propulsion Lab
View GitHub Profile
@multiplemonomials
multiplemonomials / my-rc.sh
Last active May 7, 2018 09:34
Bash/Zsh rc file functions to make life easier
#options that you always want but are not the default for some reason
alias rm='rm -rf'
alias cp='cp -a'
alias mkdir='mkdir -p'
alias fgrep='grep -RIn'
# disable Oh My Zsh history sharing
unsetopt share_history
# get list of all CMake scripts in a folder
@multiplemonomials
multiplemonomials / MultithreadBenchmarker.java
Last active May 2, 2016 05:40
Java program to test whether running a long operation in one or many threads is faster.
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
/**
* Calculates the Fibonacci sequence to 59 using varying numbers of threads
* @author Jamie
*
*/
@multiplemonomials
multiplemonomials / CommandLine.cpp
Last active March 7, 2024 14:41
Cross-platform C++ class to execute programs on both Unix and Windows. Handles program paths and arguments containing spaces. Does not require C++11.
#include <string>
#include <cstring>
#include <vector>
#include <sstream>
#include <cstdio>
#include <iostream>
#ifdef WIN32
# include <fcntl.h>
# include <windows.h>
@multiplemonomials
multiplemonomials / FindMKL.cmake
Last active May 6, 2021 23:03
CMake script to find MKL. A MKL Link Line Advisor in your pocket! (Does not work on Windows, yet) Heavily modified from the original (by hanjianwei), and battle tested across many different distros and computers, including the SDSC supercomputer Comet. Requires my other CMake gists, LibraryUtils.cmake and CheckLinkerFlag.cmake.
# - Find Intel MKL
# modified for AMBER
# Find the MKL libraries
#
# NOTE: MKL_MULTI_THREADED requires the patched FindOpenMPFixed module from the Amber-MD/cmake-buildscripts repository.
#
# Options:
#
# MKL_STATIC : use static linking. Requires linker support for the -Wl,--start-group flag.
# MKL_MULTI_THREADED: use multi-threading. Requires the FindOpenMP module
@multiplemonomials
multiplemonomials / CheckLinkerFlag.cmake
Created February 16, 2017 08:05
CMake script to check if a linker flag is valid in a given language. Modified from the CMake standard library's CheckCompilerFlag.cmake
# CheckLinkerFlag
# ------------------
#
# Checks whether a compiler supports a given linker flag.
#
include(CheckCSourceCompiles)
include(CheckCXXSourceCompiles)
include(CheckFortranSourceCompiles)
@multiplemonomials
multiplemonomials / PullParserAsyncTask.java
Last active April 12, 2017 17:55
Android AsyncTask for parsing an XML file with a minimum of boilerplate and pain. Uses the XML pull parser reference implementation library (Android's library was crashing with my file), with the javax package renamed to javay: https://mvnrepository.com/artifact/com.bea.xml/jsr173-ri
package net.multiplemonomials.densetsu.xml;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.AsyncTask;
import android.util.Log;
import com.bea.xml.stream.events.EntityReferenceEvent;
import java.io.InputStream;
@multiplemonomials
multiplemonomials / CheckLinkerFlag.cmake
Last active May 5, 2017 06:11
CMake script to check if a linker flag is supported. Based on a certain StackOverflow answer, and modified from the standard library CheckCompilerFlag.cmake. Required for FindMKL.cmake.
# CheckLinkerFlag
# ------------------
#
# Checks whether a compiler supports a given linker flag.
#
include(CheckCSourceCompiles)
include(CheckCXXSourceCompiles)
include(CheckFortranSourceCompiles)
@multiplemonomials
multiplemonomials / SociLazyStatement.h
Last active October 26, 2017 23:44
Wrapper around a Soci (SQL library for C++) statement that allows you to bind variables at execution time, and not before then. Helps you improve performance by making statements class variables.
//
// Created by Jamie on 5/12/2017.
//
#ifndef SOCI_LAZYSTATEMENT_H
#define SOCI_LAZYSTATEMENT_H
#include <soci/core/soci.h>
#include <soci/core/session.h>
@multiplemonomials
multiplemonomials / LibraryUtils.cmake
Created January 25, 2018 09:23
CMake script that can determine various bits of information about library files, including whether or not they are shared libraries.
# Script containing several advanced functions for handling libraries in CMake.
# linker flag prefix -- if a link library starts with this character, it will be ignored by import_libraries()
# this is needed because FindMKL can return linker flags mixed with its libraries (which is actually the official CMake way of doing things)
if(TARGET_WINDOWS AND NOT MINGW)
set(LINKER_FLAG_PREFIX "/") # stupid illogical MSVC command-line format...
else()
set(LINKER_FLAG_PREFIX "-")
endif()
@multiplemonomials
multiplemonomials / RandomAccessBuffer.java
Last active March 7, 2018 10:45
Java collection that implements a fixed-length buffer where adding a new element deletes the oldest element. Uses a fixed array internally, so insertion and access are O(1), and do not cause any memory allocations.
package frctest.gui;
/*
*
* Circular queue with a fixed size.
* Supports random access.
* The first element enqueued has index zero, and enqueueing another element will increment existing elements' indexes by 1.
* Enqueue()ing more than maxSize elements will overwrite the highest-index element.
*
* This class copyright (c) Jamie Smith