Skip to content

Instantly share code, notes, and snippets.

View Jontruiz1's full-sized avatar
🧹
Organization

Jonathan Ruiz Jontruiz1

🧹
Organization
View GitHub Profile
@Jontruiz1
Jontruiz1 / DFS.py
Created March 17, 2023 05:09
Portion of an NxN DFS PuzzleState solver made for my university class
if (curr_s == goal) {
solution.push_back(curr_move); // push current node into solution
// starts from end of closed and finds the current parent while setting the curr state to that parent. Pushes these parents to the solution
for (auto it = closed.rbegin(); it != closed.rend() && !(it->getState().isNullState()); ++it) {
if (it->getState() == curr_move.getParent()) {
solution.push_back(*it);
curr_move = *it;
it = closed.rbegin();
}
@Jontruiz1
Jontruiz1 / DogsAndCats.py
Created March 17, 2023 05:04
Snippet of code that sends a random dog/cat pic pulled from the dog.ceo api and thecat api
@commands.command(brief='Gives a random dog pic', description='Gives a random dog pic')
async def dogceo(self, ctx):
url = 'https://dog.ceo/api/breeds/image/random'
async with aiohttp.ClientSession() as session:
async with session.get(url) as r:
if(r.status==200):
await ctx.send(('😒\n' if (random.randint(0, 10)) < 2 else '') + (await r.json())['message'])
else:
await ctx.send('Something went wrong accessing the dogs')
@Jontruiz1
Jontruiz1 / Roshambo.py
Created March 17, 2023 05:01
A small rock, paper, scissors game made for my discord bot that uses emojis as the player choice
@commands.command(brief="Rock, paper, scissors", description='Play a game of rock, paper, scissors')
async def roshambo(self, ctx):
message = ctx.message
computer_choice = random.randint(0, 2)
player_choice = 0
play = True
wins = 0
losses = 0
draws = 0
games = 0
@Jontruiz1
Jontruiz1 / Data.py
Created March 16, 2023 06:43
Integration with mongodb to access taco count and pet count for the discord python bot
@commands.command(brief='Eat a taco', description='Makes the cat eat a taco and increments the public taco counter')
async def taco(self, ctx):
# create a string from message author and query to see if they have said this command before
author = '{}'.format(ctx.message.author)
query = {author : {'$exists' : True}}
cursor = botmain.taco_collection.find_one(query)
# if author does not exist, create and set to 1 for taco count
if(cursor == None):
botmain.taco_collection.update_one({'_id' : botmain.taco_result['_id']},
{'$set':
@Jontruiz1
Jontruiz1 / Weather.py
Created March 16, 2023 06:36
Small portion of my discord bot that uses the openweathermap api to grab the weather given by argument
@commands.command(Brief='Gets the weather', description="Gets the current weather in a city, format='=weather cityname' ")
async def weather(self, ctx, *args):
API_Key = MY_SPECIFIC_API_KEY_HERE
city_name = ''
for word in args:
city_name += str(word + ' ')
city_name = city_name[:-1]
# Provide a valid city name
url = f"http://api.openweathermap.org/data/2.5/weather?q={city_name}&appid={API_Key}"
@Jontruiz1
Jontruiz1 / TSP.cpp
Last active March 16, 2023 06:33
A small snippet of a dynamic programming solution to the TSP
#include <iostream>
#include <fstream>
#include <bitset>
#include <string>
#include <vector>
using namespace std;
for (auto s = V.begin(); s != V.end()-1; s++) {
bitset<32> A = *s;
auto aVal = A.to_ulong();