This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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]]'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
''' |