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 / 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 / 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 / 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 / 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 / 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 / example-cog-usage.py
Last active May 2, 2021 08:43
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 / discord-custom-help-command.py
Last active January 2, 2024 19:32
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