Skip to content

Instantly share code, notes, and snippets.

View uncompiled's full-sized avatar
🤠

Chris Nguyen uncompiled

🤠
View GitHub Profile
@uncompiled
uncompiled / merge_sort.py
Last active December 22, 2017 18:02
Merge Sort Algorithm
def merge_sort(input_list):
"""
merge_sort is a divide-and-conquer algorithm that repeatedly breaks
down the large task of sorting into smaller sub-problems that are
much easier given the following insight:
Insight 1: If the list only contains 1 element, it's already sorted.
Insight 2: If you have two lists that are already sorted, you can merge
the two sorted lists to create a larger sorted list.
@uncompiled
uncompiled / selection_sort.py
Last active October 29, 2017 23:03
Selection Sort (Imperative)
def selection_sort(input_list):
# Save the length of the list
n = len(input_list)
# NOTE: In Python, enumerate returns an index, value pair.
# The _ means that we're ignoring the value.
for current_index, _ in enumerate(input_list):
# Save the location of the smallest item in the list
smallest_index = current_index
@uncompiled
uncompiled / array_splicing.py
Last active September 2, 2017 21:11
Array Splicing in Python
# Here's a list of 5 people.
example_array = ["Alice", "Bob", "Jess", "Lisa", "Susan"]
middle = len(example_array) // 2
# This is shorthand for saying: "Give me the first half of the array"
# This is equivalent to example_array[0:middle]
first_half = example_array[:middle]
# ['Alice', 'Bob']
@uncompiled
uncompiled / binary_search.py
Last active September 5, 2017 16:34
Binary Search Algorithm (Recursive)
def binary_search(ordered_list, search_item):
# If the length of the list is zero, it's empty,
# so the search_item can't be in the list.
if len(ordered_list) == 0:
return False
# Otherwise, let's try to find the item...
else:
middle_item = len(ordered_list) // 2
@uncompiled
uncompiled / pagebuilder-nile-configs.r
Last active February 2, 2017 19:48
R script for querying application configurations in nile.yml
library(yaml)
# setwd("~/directory/to/nile/configs")
# Create data frame with desired input fields
yamlFile <- yaml.load_file("nile.yml")
# Load configurations into a dataframe
df <- data.frame(
lapply(
@uncompiled
uncompiled / bizet.rb
Last active February 7, 2016 14:46
Fun with Bizet's Habanera for Sonic Pi
# Mixer ########################################
theme_channel = 1
bass_channel = 0
slicer_channel = 0
sparkle_channel = 0
# Fader ########################################
overall_volume = 1
bass_volume = 0.5
sparkle_volume = 1
sparkle_speed = 0.125
@uncompiled
uncompiled / hello.rb
Last active March 19, 2023 14:35
Hello by Adele written for Sonic Pi
# Hello... World
use_bpm 75
use_synth :fm
in_thread do
loop do
cue :tick
sleep 1
end
end