Skip to content

Instantly share code, notes, and snippets.

View Makiyu-py's full-sized avatar

Makiyu Makiyu-py

View GitHub Profile
@Makiyu-py
Makiyu-py / bubbleSort.kt
Created January 11, 2022 13:22
A Kotlin Implementation of Bubble Sort :D (bubble sort is the starter "project" that I do when learning new langs)
fun main() {
var arr = arrayOf(4, 1, 3, 7, 6, 5, 8, 2)
println(arr.contentToString())
for (i in 1..arr.size) {
for (j in 0..arr.size-i-1) {
if (arr[j] > arr[j+1]) {
arr[j] = arr[j+1].also { arr[j+1] = arr[j] }
}
var outArr = arr.contentToString()
println("iter $i.$j | $outArr")
@Makiyu-py
Makiyu-py / lettersum.swift
Last active November 2, 2021 07:33
Coding Challenge #399 from r/dailyprogrammer implemented in Swift
// Day 3 of learning Swift, trying out coding challenges!
// from https://www.reddit.com/r/dailyprogrammer/comments/onfehl/20210719_challenge_399_easy_letter_value_sum/
// Instructions:
// Assign every lowercase letter a value, from 1 for a to 26 for z. Given a string of lowercase letters, find the sum of the values of the letters in the string.
func lettersum(_ str: String) -> Int {
let lowerStr = str.lowercased()
let letterVals: [Character: Int] = [
"a": 1,"b": 2, "c": 3, "d": 4, "e": 5, "f": 6, "g": 7, "h": 8, "i": 9, "j": 10, "k": 11, "l": 12, "m": 13,
@Makiyu-py
Makiyu-py / binarySearchonStrings.js
Created July 26, 2021 13:56
Binary Search (that gives multiple results depending on the matches) for an array of strings!
// this is originally for a search function for my
// twemoji-search Vue app (https://github.com/Makiyu-py/twemoji-search)
// but I found that fuzzy search existed behind my back
// the whole time so I switched to that but I don't
// want this binary search code floating in the wilderness
// of the repo's commit history, so I made this gist!
// btw this is based on Cedric Dugas' own implementation
// of the binary search algorithm on js, I just modified
// it to be "modern" I guess.
<html>
<head>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/lib/p5.js"></script>
<script src="sketch.js"></script>
</head>
<body>
<main></main>
</body>
</html>
@Makiyu-py
Makiyu-py / move_dbs_to_one.js
Last active June 17, 2021 11:14
Move all of your collections from different dbs to a specific db on MongoDB using Node.JS! (based on this stackoverflow answer (https://stackoverflow.com/a/54715607/14614326))
// don't forget to init npm first
// npm init -y
// npm install mongodb
const { MongoClient } = require('mongodb');
// Replace the uri string with your MongoDB deployment's connection string.
const uri =
'mongodb://[username:password@]host1[:port1][,...hostN[:portN]][/[defaultauthdb][?options]]';
@Makiyu-py
Makiyu-py / leaf_stem_diagram.py
Last active January 27, 2022 13:34
Creating a stem-and-leaf diagram/plot in 40~ lines of python code!
# import time
def make_stemnleaf_diagram(data: list, no_of_spaces: int=3):
# start_time = time.time()
# Storing the list data as a dict
dict_data = {}
for i in data:
i = str(i)
starts = i[:-1]
@Makiyu-py
Makiyu-py / progress_bar.py
Created February 11, 2021 02:12
A Progress Bar in 5 Lines of Python Code!
def create_progbar(total: int, current: int, *, bar_size: int = 20, comp="🟩", incomp="⬜"):
if current > total: return comp * bar_size, round((current / total) * 100, 2)
bar = ""
for i in range(bar_size): bar += comp if len(bar) < int(round(bar_size * (current / total))) else incomp
return bar, current / total
# Showing off outputs
for cur in [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]: # too lazy to add
pb, percentage = create_progbar(100, cur,
@Makiyu-py
Makiyu-py / pingcmd.py
Created December 26, 2020 14:16
First Gist! A really basic ping cmd using discord.py
from discord.ext import commands
def letteremoji(letter):
'''
Converts a letter to a discord-syntax (uppercase) emoji
Params:
letter - the letter you want to convert to a emoji (only works with the latin alphabet)
'''