Skip to content

Instantly share code, notes, and snippets.

View Kenny2github's full-sized avatar
🏫
University

AbyxDev Kenny2github

🏫
University
View GitHub Profile

Keybase proof

I hereby claim:

  • I am kenny2github on github.
  • I am kenny2crypto (https://keybase.io/kenny2crypto) on keybase.
  • I have a public key ASDMFd_UECCnVxFrIXQ0wrrgsUZkJ28JWqYxYNtyP6Sriwo

To claim this, I am signing this object:

@Kenny2github
Kenny2github / socket-forwarding.py
Last active February 11, 2019 09:52
Forward a message sent by one client to the rest of the clients. Messages sent from clients using one path are not forwarded to other paths. Requires the `websockets` Python library.
from __future__ import print_function
import asyncio
from sys import argv
import websockets
connected = {}
def handler(sock, path):
if path not in connected:
connected[path] = set()
@Kenny2github
Kenny2github / copy-comment.user.js
Last active August 2, 2020 18:35
Copy Scratch comment links
// ==UserScript==
// @name Comment IDs
// @version 0.1
// @description Get Scratch comment IDs
// @author Kenny2github
// @match https://scratch.mit.edu/*
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js
// @require https://gist.github.com/raw/2625891/waitForKeyElements.js
// @updateURL https://gist.githubusercontent.com/Kenny2github/a25dff9c52c90d6f062209df43ef0200/raw/copy-comment.user.js
// ==/UserScript==
@Kenny2github
Kenny2github / vortex.py
Last active June 5, 2019 13:03
Vortex Sort - swirl elements into sorted order!
def vortex_sort(arr):
"""Swirl the array into order.
Guaranteed to only use < for comparison, so use any objects you like.
"""
arlen = len(arr)
rs = []
mult = 1
last = 0
while last < arlen:
number = mult * 4
@Kenny2github
Kenny2github / vigenere.py
Created July 25, 2019 16:28
Transform text with the vigenere cipher.
LETTERS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
def vigenere(string, key, direction=1):
"""Transform text with the vigenere cipher.
``string`` is the text to transform.
``key`` is the key to use in the process.
``direction`` is the direction of transformation:
1 for encoding, and -1 for decoding.
@Kenny2github
Kenny2github / a_star.py
Last active August 20, 2019 07:23
A* algorithm implemented in Python.
import math
import random
from random import randint
from types import SimpleNamespace as Record
import pygame
from pygame.locals import *
SIZE = WIDTH, HEIGHT = 640, 360
HALFWIDTH, HALFHEIGHT = WIDTH // 2, HEIGHT // 2
BLOCS = BLOCW, BLOCH = 20, 20
@Kenny2github
Kenny2github / generalized_exp.py
Created November 30, 2021 04:56
A Python implementation of the exponential function generalized to anything that supports Taylor series operations.
def exp(z, zero=None, one=None, equality=lambda a, b: a == b):
"""Raise e to the power of z.
z need only support the following:
- Addition with its own type
- Multiplication with its own type
- Multiplication with float
Provide ``zero`` if z - z != the zero of its type.
This function will probably not produce correct results
if this is the case, but it is provided for completeness.
@Kenny2github
Kenny2github / resistors.py
Last active April 17, 2022 02:05
Compute the equivalent impedance between two nodes.
from __future__ import annotations
from itertools import combinations
class Node:
components: set[Component]
num: int = 1
def __init__(self, components: set = None) -> None:
self.num = type(self).num
@Kenny2github
Kenny2github / combinatorics.ex
Last active June 9, 2022 04:19
Implementation of combinations and permutations in Elixir
defmodule Combinatorics do
def combinations(_, 0), do: [[]]
def combinations([], _), do: []
def combinations([head | rest], n) do
(for item <- combinations(rest, n - 1), do: [head | item]) ++ combinations(rest, n)
end
def permutations([]), do: [[]]
def permutations(list) do
for h <- list, t <- permutations(list -- [h]), do: [h | t]
@Kenny2github
Kenny2github / squaredle.exs
Created June 9, 2022 07:03
Generate words for Squaredle - https://squaredle.app
defmodule Squaredle do
def find_word(row, col, word, board, past_path) do
coords = [
{row + 1, col + 1},
{row + 1, col + 0},
{row + 1, col - 1},
{row + 0, col + 1},
{row + 0, col - 1},
{row - 1, col + 1},
{row - 1, col + 0},