Skip to content

Instantly share code, notes, and snippets.

@cabauman
cabauman / commit_messages_to_release_notes.py
Created March 26, 2024 00:28
A simple Python script that parses Plastic SCM conventional commit messages and outputs categorized release notes
import subprocess
import re
def get_last_label():
output = subprocess.check_output(["cm", "find", "label", "order by date desc", "limit 2", "--format={changeset}", "on repository 'dmo-softbank-smartcity-envisioning'", "--nototal"])
changesetids = output.decode("utf-8").splitlines()
if changesetids:
return changesetids[-1]
else:
return None
@cabauman
cabauman / Multiples of 3 and 5
Last active January 26, 2016 11:10
Find the sum of all the multiples of 3 or 5 below 1000. Blog post: http://www.coltbauman.com/blog/programming/12-programming-level-up
// METHOD 1: Least efficient. O(n) time complexity.
int LoopAndTest()
{
int a = 3, b = 5;
int sum = 0;
int limit = 1000;
for( int i = 0; i < limit; ++i )
{
if( i % a == 0 || i % b == 0 )
@cabauman
cabauman / Even Fibonacci Numbers
Last active January 26, 2016 11:20
By considering the terms in the Fibonacci sequence whose values do not exceed four million, find the sum of the even-valued terms. Blog post: http://www.coltbauman.com/blog/programming/20-even-fibonacci-numbers
// METHOD 1: Least efficient. O(n) time complexity.
int LoopAndTestMethod()
{
int sum = 0;
int a = 1, b = 1, c = a + b;
int limit = 4000000;
while( c < limit )
{
if( c % 2 == 0 )
template<class T>
void SelectionSort( T* arr, int n )
{
for( int slot = 0; slot < n - 1; ++slot )
{
int minIdx = slot;
for( int testIdx = slot + 1; testIdx < n; ++testIdx )
{
if( arr[testIdx] < arr[minIdx] )
minIdx = testIdx;
@cabauman
cabauman / MergeSort2
Last active January 26, 2016 14:53
Temporary array created in the Merge function
template<class T>
void MergeSort( T* arr, int startIdx, int endIdx )
{
if( startIdx < endIdx )
{
int midIdx = startIdx + ( endIdx - startIdx ) / 2;
MergeSort( arr, startIdx, midIdx );
MergeSort( arr, midIdx + 1, endIdx );
Merge( arr, startIdx, midIdx, endIdx );
}
@cabauman
cabauman / MergeSort1
Last active January 26, 2016 14:54
Temporary arrays created in the MergeSort function
template<class T>
void MergeSort( T* arr, int n )
{
if( n < 2 )
return;
int leftSize = n / 2;
int rightSize = n - leftSize;
T* left = new int[leftSize];
template<class T>
void BubbleSort( T* arr, int n )
{
for( int pass = 1; pass < n; ++pass )
{
bool didSwap = false;
for( int i = 0; i < n - pass; ++i )
{
if( arr[i] > arr[i + 1] )
{
template<class T>
void InsertionSort( T* arr, int n )
{
for( int pass = 1; pass < n; ++pass )
{
int slot = pass;
T val = arr[slot];
while( slot > 0 && val < arr[slot - 1] )
{
arr[slot] = arr[slot - 1];