Skip to content

Instantly share code, notes, and snippets.

View TheOnlyWayUp's full-sized avatar
📰
Democratizing information

Dhanush R TheOnlyWayUp

📰
Democratizing information
View GitHub Profile
import pkg_resources
from subprocess import call
packages = [dist.project_name for dist in pkg_resources.working_set]
#Uses list comprehension to create a list of all packages installed, and then get their names.
call("pip install --upgrade " + ' '.join(packages), shell=True)
#Call is like os.system, it runs pip install upgrade and the join essentially seperates all the packages with a " ", ex if you had the packages discord and setuptools installed, the list would become ["discord", "setuptools"] and it would run pip install -upgrade discord setuptools

A Cool Help Command - Full example of how it looks in action at the bottom image image

import discord, discord_colorize
from discord.ext import commands
@TheOnlyWayUp
TheOnlyWayUp / cog.py
Created February 13, 2022 08:39
Creates a list of all loaded cogs, made in response to https://discord.com/channels/434207294184620043/434352882507317250/942336370544898088 in the r/discord_bots discord server.
def setup(bot):
bot.loadedCogs.append('cog name')
def teardown(bot):
bot.loadedCogs.remove('cog name')
# https://discordpy.readthedocs.io/en/stable/ext/commands/extensions.html?highlight=load#cleaning-up
@TheOnlyWayUp
TheOnlyWayUp / readme.diff
Last active February 22, 2022 06:40
Contact Me
+Thanks for checking my profile out
+Contact me at TheOnlyWayUp#1231
@TheOnlyWayUp
TheOnlyWayUp / imageFunctions.py
Last active March 6, 2022 14:01
Example of BytesIO and PIL for modifying images without saving them
domain = 'watermark' # just an example of how to use bytesio with PIL, works better if you know more about the images you're using instead of using random ones which can have random dimensions.
import aiohttp
from urllib.parse import unquote
from io import BytesIO
from PIL import Image, ImageDraw, ImageFont
async def returnRandomCat():
async with aiohttp.ClientSession() as session:
async with session.get("https://aws.random.cat/meow") as resp:
<!DOCTYPE html>
<html lang="en">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="keywords" content="{{ status_code }}, {{ detail }}">
<meta charset="utf-8">
<meta property="og:title" content="">
"""
This attempts to abstarct away the standard way of using `__init__`,
the problem it tries to solve is the repetetiveness of using init purely
to store it's parameters into the instance under the exactly same name, i.e.:
class Stock:
def __init__(name, shares, price):
self.name = name
self.shares = shares
self.price = price
"""
@TheOnlyWayUp
TheOnlyWayUp / README.md
Last active June 25, 2022 07:47
I was having some trouble with Zoho's OAuth, after lots of research, this is what I came up with. The goal of using Zoho's OAuth is mostly to verify that the person logging in is from a specific domain..

Zoho OAuth Identification Example

The goal of this snippet is to help you figure out the email/identity of the person OAUthing to your application. Made this to help out anyone else that's trying to do the same thing.

main.py - Just a short aiohttp snippet regarding what requests you need to make to get the access token, and the user's information.

example_usage.py - A FastAPI implementation of this.

NOTE = You need to select the server based applications option when creating your Application at Zoho's Console. Then you need to run a webserver, add that server's domain (you need to have a domain iirc) as an authorized redirect url. Think your_domain.com/callback.

@TheOnlyWayUp
TheOnlyWayUp / fibo.py
Last active August 2, 2022 12:43
Basic OOP-Based Fibonacci Sequence in Python
class UserList:
def __init__(self, initlist: list = []):
self.data = initlist
class FiboList(UserList):
def __init__(self):
super().__init__([0, 1])
def __next__(self):
sum_ = sum(self.data)
@TheOnlyWayUp
TheOnlyWayUp / App.svelte
Last active August 21, 2022 16:52
The aim of this gist is to explain how one can modify attributes in their HTML (<html>) tag when working with a svelte project.
<script>
export let HTMLParent; <!-- Declares HTMLParent as a prop -->
let DataTheme = "business";
HTMLParent.setAttribute('data-theme', DataTheme) <!-- Sets the data-theme attribute on the HTML Tag to the value of DataTheme, leading to `<HTML data-theme="business">`.
</script>
<!--
That's it, we've managed to grab and modify the top-level <HTML> Tag. You can make further modifications to it by accessing the HTMLParent variable