Skip to content

Instantly share code, notes, and snippets.

@hobelinm
hobelinm / gist:4192020
Created December 3, 2012 01:24
Bubble Sort - C++
template<typename Comparable> void bubbleSort(vector<Comparable> &a);
template<typename Comparable> void bubbleSortInverted(vector<Comparable> &a);
template <typename Comparable>
void bubbleSort(vector<Comparable> &a)
{
bool sorted = false;
for(int pass = 1; pass < a.size() && !sorted; pass++)
{
@hobelinm
hobelinm / Get-LineCount.ps1
Last active December 14, 2015 19:39
This is a simple script for getting the non-empty lines for your source code files written in PowerShell
[CmdletBinding()]
param (
[parameter(Mandatory = $false, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)]
[ValidateNotNullOrEmpty()]
[string]$Path = (Get-Location),
[parameter(Mandatory = $false, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)]
[ValidateNotNullOrEmpty()]
[string[]]$Files = ("*.cpp", "*.h"),
@hobelinm
hobelinm / Set-AnimatedProgress.ps1
Last active August 29, 2015 13:57
A simple animated Write-Progress sample made in PowerShell
$xMessage = @()
$xMessage += " --------------# | \\ // |# | \\// |# | //\\ |# | // \\ |# --------------".Replace( `
"#", (" " * ($host.UI.RawUI.BufferSize.Width - 16 - 4)) )
$xMessage += " ----------------# | \\ // |# | \\ // |# | // \\ |# | // \\ |# ----------------".Replace( `
"#", (" " * ($host.UI.RawUI.BufferSize.Width - 17 - 4)))
$chgIdx = 0
$index = 0
while($true)
{
@hobelinm
hobelinm / MergeSort.cpp
Created March 9, 2014 06:16
Simple implementation of Merge Sort Algorithm in C++
// Fill a random vector
template <typename Comparable>
void fillRandom(vector<Comparable> &iArray, Comparable range)
{
srand((unsigned)time(0));
for(Comparable i = 0; i < iArray.size(); i++)
{
iArray[i] = rand() % range;
}
}
@hobelinm
hobelinm / InsertionSort.cpp
Created March 9, 2014 06:29
Simple implementation of Insertion Sort algorithm in C++
// Fill an array with random numbers
template <typename Comparable>
void fillRandom(vector<Comparable> &iArray, Comparable range)
{
srand((unsigned)time(0));
for(Comparable i = 0; i < iArray.size(); i++)
{
iArray[i] = rand() % range;
}
}
@hobelinm
hobelinm / BubbleSort.cpp
Created March 9, 2014 06:33
Simple implementation of Bubble Sort algorithm
// Random Generator
template <typename Comparable>
void fillRandom(vector<Comparable> &iArray)
{
srand((unsigned)time(0));
for(vector<Comparable>::size_type i = 0; i < iArray.size(); i++)
{
iArray[i] = rand();
}
}
@hobelinm
hobelinm / SelectionSort.cpp
Created March 9, 2014 06:40
Simple implementation about Selection Sort in C++
#include <iostream>
#include <vector>
#include <ctime>
// A random number generator
void fillRandom(vector<int> &iArray)
{
srand((unsigned)time(0));
for(int i = 0; i < iArray.size(); i++)
{
@hobelinm
hobelinm / InputBox.ps1
Created March 9, 2014 06:49
Simple dialog box in PowerShell
# Load libraries
[void][System.Reflection.Assembly]::LoadWithPartialName('Microsoft.VisualBasic')
# Selection box
$input = [Microsoft.VisualBasic.Interaction]::MsgBox("Do you agree?", 'YesNoCancel,Question', "Respond Please")
# Process input as desired
switch($input)
{
'Yes'
@hobelinm
hobelinm / DynamicLoadingTest.ps1
Created March 9, 2014 22:58
Proof of concept for dynamic loading of functions made in PowerShell
# Considering the test function in a given location
# you can ignore the following line
"function test{""Original Test""}" > test.ps1
# This is a sample of the stub that would peform the function of
# finding and downloading the original function. For the sake of
# the test we can consider that's already done in test.ps1 in $PWD
function test
{
"Stub Test"
@hobelinm
hobelinm / CustomInput.html
Created October 15, 2014 05:35
Customizable Input HTML
<!DOCTYPE html>
<html>
<body>
<h1>Customizable Form</h1>
<p>A custom form will show up with appropriate fields to complete.</p>
<select id="select" onchange="leaveChange()">
<option value="none">Select a Car</option>