Skip to content

Instantly share code, notes, and snippets.

View JosephTLyons's full-sized avatar
🛏️

Joseph T. Lyons JosephTLyons

🛏️
View GitHub Profile
@JosephTLyons
JosephTLyons / PlaySound.swift
Created July 18, 2019 11:51
Angela Yu Lesson 87: Create a Method to Contain the Sound Playing Functionality (Solution)
@IBAction func notePressed(_ sender: UIButton) {
playSound("note" + String(sender.tag))
}
func playSound(_ fileName: String) {
let soundURL = Bundle.main.url(forResource: fileName, withExtension: "wav")
do {
try audioPlayer = AVAudioPlayer(contentsOf: soundURL!)
}
catch {
@JosephTLyons
JosephTLyons / Destini.swift
Last active July 19, 2019 07:06
Angela Yu Section 10: Coding Challenge #3 - Control Flow - Build a Story App Life Lifeline (Solution)
//
// ViewController.swift
// Destini
//
// Created by Philipp Muellauer on 01/09/2015.
// Copyright (c) 2015 London App Brewery. All rights reserved.
//
import UIKit
#!/usr/bin/env python3
values = []
for i in range(5):
values.append(int(input("Enter a number: ")))
average = sum(values) / len(values)
if average <= 50:
@JosephTLyons
JosephTLyons / binary_search.rs
Last active February 2, 2020 16:58
binary_search in Rust
use std::cmp::Ordering;
#[allow(dead_code)]
fn binary_search<T: std::cmp::Ord>(n: T, array: &[T]) -> Option<usize> {
if !array.is_empty() {
let mut lower_bound = 0;
let mut upper_bound = array.len() - 1;
let mut midway_point;
while lower_bound <= upper_bound {
@JosephTLyons
JosephTLyons / main.cpp
Last active July 6, 2020 01:36
A hacky way to get a string from a float in C++
// A hacky way to get a string from a float in C++
#include <iostream>
#include <math.h>
std::string float_to_string(const double& number, int precision)
{
int adjustment_int = pow(10, precision);
int intermediate_value = number * adjustment_int;
double truncated_float = intermediate_value / (double) adjustment_int;
@JosephTLyons
JosephTLyons / main.cpp
Last active July 10, 2020 00:50
Another floatToString snippet, this time, relying on CHOC (link in the code)
//
// main.cpp
// CHOC_test
//
// Created by Joseph Lyons on 7/9/20.
// Copyright © 2020 Joseph Lyons. All rights reserved.
//
// Find the choc_FloatToString.h at:
// https://github.com/julianstorer/choc
#!/usr/bin/env python3
def print_english_version_of_number(integer):
ones_values = ["one", "two", "three", "four", "five", "six", "seven", "eight", "nine"]
teens_values = ["eleven", "twelve", "thirteen", "fourteen", "fifeteen", "sixteen", "seventeen", "eighteen", "nineteen"]
tens_values = ["ten", "twenty", "thirty", "forty", "fifety", "sixty", "seventy", "eighty", "ninety"]
integer_hundreds_value = integer // 100
integer %= 100
integer_tens_value = integer // 10
@JosephTLyons
JosephTLyons / random_exercise.py
Last active July 27, 2020 04:20
Prints odd numbers whose individual digits are odd and are not repeated
#!/usr/bin/env python3
# Only prints odd numbers whose individual digits are odd and are not repeated
def meets_criteria(number):
if number % 2 == 0:
return False
digits = []
while number > 0:
#!/usr/bin/env python3
def print_square_wave(character, length, period):
for i in range(0, period):
for _ in range(0, length - 1):
print(character)
for _ in range(0, length):
print(character + " ", end="")
@JosephTLyons
JosephTLyons / main.py
Last active December 7, 2020 07:36
A Python example of dynamic programming for the recursive Fibonacci sequence algorithm
#!/usr/bin/env python3
from enum import auto, Enum, unique
def fib_recursive(n, calculated_results=None):
if calculated_results is not None and n in calculated_results:
result = calculated_results[n]
else: