Skip to content

Instantly share code, notes, and snippets.

View dmdrummond's full-sized avatar

Daniel Drummond dmdrummond

  • Lethbridge, Alberta, Canada
View GitHub Profile
@dmdrummond
dmdrummond / permutations.kt
Created December 9, 2019 04:26
Permutation generation using Heaps algorithm in Kotlin
// Usage: listOf(1, 2, 3).permutations()
// Output: [[1, 2, 3], [2, 1, 3], [3, 1, 2], [1, 3, 2], [2, 3, 1], [3, 2, 1]]
fun <V> List<V>.permutations(): List<List<V>> {
val retVal: MutableList<List<V>> = mutableListOf()
fun generate(k: Int, list: List<V>) {
// If only 1 element, just output the array
if (k == 1) {
retVal.add(list.toList())
@dmdrummond
dmdrummond / chairunner.cpp
Created September 13, 2015 00:08
Quick and dirty runner for ChaiScripts
#include <chaiscript/chaiscript.hpp>
#include <chaiscript/chaiscript_stdlib.hpp>
#include <string>
#include <strstream>
#include <fstream>
int main(int argc, char ** argv) {
if (argc != 2) {
std::cout << "Usage chairunner path_to_script\n";
@dmdrummond
dmdrummond / AlphaGradient.java
Last active August 29, 2015 13:58
Method to add a transparent gradient to the right hand side of a bitmap
/**
* Adds a transparent gradient to the right edge of a bitmap
*
* Released into the public domain
*
* Created by dmdrummond on 05/04/2014.
*/
/**
* Adds a transparent gradient to the right edge of the image