Skip to content

Instantly share code, notes, and snippets.

View nonchris's full-sized avatar
👀
Why isn't it moving?

Chris G nonchris

👀
Why isn't it moving?
View GitHub Profile
@nonchris
nonchris / discord-custom-help-command.py
Last active August 13, 2024 03:40
A kinda advanced custom "help" command for your Discord.py bots!
import discord
from discord.ext import commands
from discord.errors import Forbidden
"""This custom help command is a perfect replacement for the default one on any Discord Bot written in Discord.py!
However, you must put "bot.remove_command('help')" in your bot, and the command must be in a cog for it to work.
Original concept by Jared Newsom (AKA Jared M.F.)
[Deleted] https://gist.github.com/StudioMFTechnologies/ad41bfd32b2379ccffe90b0e34128b8b
Rewritten and optimized by github.com/nonchris
@nonchris
nonchris / example-cog-usage.py
Last active June 10, 2024 14:08
Discord.py: Get Role by Role Name, ID or mention
import re
import discord
"""
A function that returns the matching role-id(s) in a list (as integers)
Needed Arguments: Comamnd-Context and Role-ID/ Role-Mention/ Role-Name (as a string)
The function will return a tuple of values that contains two values:
- A list with all matching role-id (should be one most of the times)
- The length of that list as secondary return value
@nonchris
nonchris / converter.py
Created November 7, 2020 12:47
symbol replacer for file content
def conv(file: str, new="converted-file.txt", symbol=",", rep=".") -> str:
"""
Needs: filename
Optional: filename, symbol to replace, symbol to replace with
- reads data, replaces a symbol with an other symbol of choice
- writes new data in file and returns filename
"""
with open(file, "r") as f: #open file
read = f.read() #read content
repl = read.replace(symbol, rep) #replace symbol
@nonchris
nonchris / telegram-dialogue.py
Last active June 9, 2022 23:13
Telegram Bot Dialogue Keyboard (minimal example)
"""
This code shows how to create a custom keyboard for a telegram bot
Using https://github.com/python-telegram-bot/python-telegram-bot
"""
from telegram.ext import Updater
from telegram.ext import CommandHandler
from telegram.ext import MessageHandler, Filters
from telegram import Bot
from telegram import KeyboardButton
from telegram import ReplyKeyboardMarkup
@nonchris
nonchris / while_loop.tex
Created June 12, 2021 22:05
A basic loop written in tex
% NOTE: I do not guarantee that this is the best way of doing it
% but I wanna share it anyways since I can't really find any (commented) example code like this.
% ---
% command to print numbers one per line
% paste somewhere into your document (can be preamble or document itself)
% init counter variable
\newcount\i
@nonchris
nonchris / PlaceMNIST.py
Last active June 22, 2021 09:23
A task for the lecture 'computational itelligence' at the univeristy of bonn. It places three images from the MNIST dataset 'randomized' on a 64x64 image.
import random
from typing import Tuple, List
import numpy as np
import numpy.typing as npt
import torch
"""
This is a sub-task for the lecture 'computational itelligence' at the univeristy of bonn.
It places three images from the MNIST dataset 'randomized' on a 64x64 image.
@nonchris
nonchris / array_speed.py
Created July 3, 2021 15:06
Some quick array operations using python lists and numpy to get a feeling for performance
import sys
import time
import numpy as np
"""
Just a quick non scientific performance test for iterables from python and numpy.
This is only meant to get a rough feeling for different performances.
"""
@nonchris
nonchris / custom-string-task.md
Last active May 2, 2022 19:42
A small task to play with function overloading and slicing

This task was migrated to github.com/nonchris/python.
The gist is no longer maintained.

Custom String

A small task to play with function overloading and slcining of elements.
Our goal is to implement a basic string-class that is mutable (parts can be changed after creation).

class CustomString:
 def __init__(self):
@nonchris
nonchris / count_bot.py
Created October 9, 2021 22:47
Discord-Bot to counts messages in a channel that fulfill certain requirements
#!/bin/env python
import os
import re
from typing import Union, Dict
import discord
import discord.errors as d_errors
from discord.ext import commands
"""
@nonchris
nonchris / few-macros.tex
Created November 6, 2021 16:06
Things I use for making my life easier using LaTeX
% OWN macros
% vereinfacht den Befehl \texttt
\newcommand{\tttt}[1]{\texttt{#1}}
% vereinfacht den Befehl \textbf
\newcommand{\ttf}[1]{\textbf{#1}}
% vereinfacht den Befehl \textbf
\newcommand{\ttsl}[1]{\textsl{#1}}
\newcommand{\ttsf}[1]{\textsf{#1}}
% underline