Skip to content

Instantly share code, notes, and snippets.

View mbove77's full-sized avatar
🏠
Working from home

Martin Bove mbove77

🏠
Working from home
View GitHub Profile
@mbove77
mbove77 / BubbleSortLoop.kt
Created July 20, 2022 22:56
Bubble sort implemented with loops in kotlin
fun bubbleSortLoop(inputArray: Array<Int>): Array<Int> {
var iterations = 1
var isSorted: Boolean
for (i in 0 until inputArray.size -1) {
isSorted = true
// This print is for see the interactions in sort algorithm
println("Iteration number: ${iterations++}")
for (j in 0 until inputArray.size -i -1) {
if (inputArray[j] > inputArray[j+1]) {
@mbove77
mbove77 / BubbleSortRecursion.kt
Last active July 20, 2022 23:15
Bubble sort with recursion implemented in kotlin
fun bubbleSort(inputArray: Array<Int>, nextIterIndex: Int = inputArray.size): Array<Int> {
// This print is for see the interactions in sort algorithm
println("iteration number ${inputArray.size - nextIterIndex+1}")
val lastIndex = nextIterIndex -1
var isSorted = true
for (i in 0 until lastIndex) {
val currentItem = inputArray[i]
val nextItem = inputArray[i+1]
@mbove77
mbove77 / BinarySearch.kt
Last active July 20, 2022 22:24
Binary search with recursion implemented in Kotlin
// The inputArray must be sorted in order to apply the binary search.
fun binarySearch(inputArray: Array<Int>, itemToSearch: Int) : Boolean {
// This print is for see the interactions in the search
println()
inputArray.forEach {
print("$it,")
}
if (inputArray.size > 1) {
if (itemToSearch == inputArray[(inputArray.size / 2) - 1]) {
@mbove77
mbove77 / optimizeAndCropImage.cloudFunction.js
Created August 21, 2018 18:21
Firebase cloud function to resize and optimize image after upload in cloud storage.
const functions = require('firebase-functions');
const gcs = require('@google-cloud/storage')();
const spawn = require('child-process-promise').spawn;
const mkdirp = require('mkdirp-promise');
const path = require('path');
const os = require('os');
const fs = require('fs');
// // Create and Deploy Your First Cloud Functions
exports.optimizeImages= functions.storage.object().onFinalize((data) => {