Skip to content

Instantly share code, notes, and snippets.

View MichaelSDavid's full-sized avatar
🐬
Just tech diving!

Michael David MichaelSDavid

🐬
Just tech diving!
View GitHub Profile
@MichaelSDavid
MichaelSDavid / playSound.swift
Created July 5, 2022 23:13
Plays a sound file in Swift for usage in iOS/Mac apps with something like a button or gesture trigger.
import AVFoundation
var player: AVAudioPlayer?
func playSound(name: String) {
// Change extension as needed
guard let url = Bundle.main.url(forResource: name, withExtension: "mp3") else { return }
do {
try AVAudioSession.sharedInstance().setCategory(AVAudioSession.Category.playback)
@MichaelSDavid
MichaelSDavid / derivative_matplotlib.py
Created July 28, 2021 06:17
Calculates the derivative of a function at a given point, finds the equation of the tangent line, and plots this on the plane with matplotkib.
from matplotlib import pyplot as plt
def function(x):
# Enter any function (example given by default)
return x**2 + 4
def graph_function():
y_points = []
x_points = []
@MichaelSDavid
MichaelSDavid / AlbertApplet.java
Created July 6, 2021 19:18
A small Java Applet that draws a minimalistic picture of Albert Einstein with a famous quote of his.
import javax.swing.JApplet;
import java.awt.*;
public class Applet extends JApplet {
// Einstein portrait
public void paint(Graphics page) {
page.drawRect(50, 50, 40, 40); // Square
page.drawRect(60, 80, 225, 30); // Rectangle
page.drawOval(75, 65, 20, 20); // Circle
page.drawLine(35, 60, 100, 120); // Line
@MichaelSDavid
MichaelSDavid / challenge18.py
Created September 9, 2020 02:02
Challenge #18 solution for TWT Discord
# Only requires the function for submission
def solution(k):
r,y = [],[]
m = 1
while m <= k:
if m % 2 == 0:
r.append(m ** 2)
else:
y.append(m ** 2)
@MichaelSDavid
MichaelSDavid / bulkRemoveWLVideos.js
Created September 4, 2020 23:43
Console script to bulk remove "Watch Later" videos on YouTube (requires old layout)
// Old view in WL: https://www.youtube.com/playlist?list=WL&disable_polymer=true
var timer = window.setInterval(function() {
var videoDeleteButton = document.querySelector('.pl-video-edit-remove')
if (videoDeleteButton) {
videoDeleteButton.click()
setTimeout(function() {
document.querySelector('.yt-uix-load-more').click()
}, 5000)
} else {
window.clearInterval(timer)
@MichaelSDavid
MichaelSDavid / military_time.cpp
Created September 4, 2020 22:57
SoloLearn Code Coach solution for Military Time in C++
#include <iostream>
#include <string>
using namespace std;
int main() {
string twelve_hr_str;
string initial_hr;
int new_hr;
string final_24_str;
@MichaelSDavid
MichaelSDavid / military_time.py
Last active September 4, 2020 22:57
SoloLearn Code Coach solution for Military Time in Python
sample_string = input()
def military_time(twelvehour_str):
if "PM" in twelvehour_str:
if len(twelvehour_str) == 8:
initial_hour = twelvehour_str[:2]
new_hour = int(initial_hour) + 12
final24_str = str(new_hour) + twelvehour_str[2:5]
else:
initial_hour = twelvehour_str[0]
@MichaelSDavid
MichaelSDavid / Notepad.java
Last active September 1, 2020 00:30
Multility notepad backend
package com.matdevtech.multility;
// Imports
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.graphics.Typeface;
import android.os.Bundle;
import android.view.LayoutInflater;
@MichaelSDavid
MichaelSDavid / PasswordGenerator.java
Last active September 1, 2020 00:15
Multility password generator backend
package com.matdevtech.multility;
// Imports
import android.annotation.SuppressLint;
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
@MichaelSDavid
MichaelSDavid / daily_int_pro_08-20-2020.py
Created August 20, 2020 20:52
Daily Interview Pro example solution for shifted string problem on 08/20/2020
def is_shifted(a, b):
shift_list = []
def shift(n, s):
tmp = [char for char in s]
shift_str = ''.join(tmp[-n:] + tmp[:-n])
return shift_str
for i in range(1, len(a)):
shift_list.append(shift(i, a))