Skip to content

Instantly share code, notes, and snippets.

View dyllandry's full-sized avatar
🍞

Dylan Landry dyllandry

🍞
  • Tactus Therapy
  • Toronto, ON, Canada
View GitHub Profile
@dyllandry
dyllandry / frequencyCounters.js
Created June 10, 2019 15:54
Frequency Counters
/**
* These two functions do the same thing.
* They check if a second array contains squared values of the first array.
* The first is slow. Every value is compared to each other.
* The second is faster, it runs through each array only once.
* The approach of the second function I refer to as a "frequency counter".
*/
function nestedLoop (array1, array2) {
if (array1.length !== array2.length) {
@dyllandry
dyllandry / bubble-sort.js
Last active June 20, 2019 15:02
Description and implementation of a bubble sort algorithm.
/**
* Named 'bubble sort' because the largest value will
* bubble to the array's end after the first pass.
*
* Instructions:
* Beginning at the start of the array and
* progressing to the end, repeatedly swap adjacent
* elements in place if they are in the wrong order.
* To sort the entire array, perform subsequent passes
* going only as far as the previously sorted element.
@dyllandry
dyllandry / selection-sort.js
Created June 20, 2019 15:13
Description and implementation of a selection sort algorithm.
/**
* Selection Sort: The name comes from the process of
* repeatedly selecting the minimum element and swapping it
* with the first unsorted element. Selection sort works
* as well by selecting and sorting maximum values.
*
* Process: Iterate through the array to find the minimum
* value. Swap the minumum value with the first
* element. Repeat this process beginning with the element
* proceeding the previously sorted value.
@dyllandry
dyllandry / insertion-sort.js
Created June 20, 2019 16:16
Description and implementation of a insertion sort algorithm.
/**
* Insertion Sort: The name comes from the process of
* maintaining a sorted subarray by which unsorted values
* are inserted within through a process of repeated
* swapping.
*
* Process:
* Maintain a sorted subarray in place that begins with
* only the array's first element. Beginning at the second
* element, repeatedly swap the current element with those
@dyllandry
dyllandry / merge-sort.js
Created June 20, 2019 18:35
Description and implementation of a merge sort algorithm.
/**
* Merge Sort: Gets its name from the process of repeatedly
* splitting the original array and merging it back together.
*
* Process:
* Repeatedly split the original array until all subarrays
* are of just one element. Remerge the subarrays and
* continuously sort the elements.
*
* Performance:
@dyllandry
dyllandry / quick-sort.js
Created June 21, 2019 15:29
Description and implementation of a quick sort algorithm.
/**
* Quick Sort: Gets its name from being... Quick...?
*
* Process:
* Pick an element of the array, a value to pivot around.
* Place all less than values before the pivot, and all the
* greater than values after the pivot. These values do not
* need to be sorted, just properly placed before or
* after the pivot value. The pivot value is now sorted.
* Repeat the process recursively on the values less than
@dyllandry
dyllandry / radix-sort.js
Created June 21, 2019 18:51
Description and implementation of a radix sort algorithm.
/**
* Radix Sort: Radix (or base) means: "the base of a
* system of numeration." Radix sorts by analyzing the
* place values of each number. Each number must be a
* whole number, or positive integer. Radix sort can be used
* with a variety of base values, though here I focus
* only on our decimal base 10 system.
*
* Process:
* Create an auxiliary array with a length of ten (one
@dyllandry
dyllandry / singly-linked-list.js
Last active June 27, 2019 12:41
Description and implementation of a singly linked list data structure.
/**
* Title: Singly Linked List
* Author: Dylan Landry
* Date: Wed 26 Jun 2019 13:38:38 EDT
* Permalink: https://gist.github.com/dyllandry/371505391a608abb9d979a1ea258cff9
*
* Description:
* A kind of data structure similar to a train.
* Each node, a container for a value, knows only of the node ahead of it.
* The list keeps references to the head node, the tail node, and the total
@dyllandry
dyllandry / doubly-linked-lists.js
Created June 27, 2019 12:42
Description and implementation of a doubly linked list data structure.
/**
* Title: Doubly Linked List
* Author: Dylan Landry
* Date: Wed 26 Jun 2019 16:00:15 EDT
* Permalink: https://gist.github.com/dyllandry/12d0a2f7f1b1cfc22169b1990bd89c2d
*
* Description:
* A kind of data structure similar to a train.
* Each node, a container for a value, knows of the node ahead of it and behind
* it. The list keeps references to the head node, the tail node, and the total
@dyllandry
dyllandry / toggle-touchpad.sh
Last active April 22, 2020 01:27
Toggle a touchpad on/off.
#!/bin/sh
# Toggles a touchpad on/off.
# Might only work computers that use xinput.
DEVICE_NAME="SynPS/2 Synaptics TouchPad"
ID=$(xinput list --id-only "$DEVICE_NAME")
IS_ENABLED=$(xinput --list-props "$DEVICE_NAME" | grep "Device Enabled" | grep -o "[01]$")
if [ $IS_ENABLED -eq 0 ]; then
xinput set-prop $ID "Device Enabled" 1