Skip to content

Instantly share code, notes, and snippets.

View JRiggles's full-sized avatar
👾

John Riggles JRiggles

👾
View GitHub Profile

Easy Pixel-Art Grass in Aseprite

Tutorial by sudo whoami

  1. Using a dark shade of green (or whatever color you like!) draw a small bunch of grass (keeping it within 16×16 is a good start)

grass sprite

  1. Save it as a custom brush via Cmd+B or Ctrl+B
  • Set the bounding box to 2× the size of the sprite from step 1 (e.g. 32×32), keeping the sprite to one corner
@JRiggles
JRiggles / smb3_lfsr.py
Last active December 21, 2023 14:03
SMB3 LFSR
from time import time # not 100% necessary, just used to seed the RNG
def nes_lfsr(seed: int) -> int:
"""
Implementation of the Linear-Feedback Shift Register RNG used by SMB3
RNG will repeat after 32,767 (0x7FFF) iterations (the maximum 15-bit
integer value) regardless of the seed
"""
@JRiggles
JRiggles / walrus hunter.py
Last active November 17, 2022 20:05
RegEx for tracking down Python 'if' and 'while' statements that might be refactorable to use the 'walrus' assignment operator ':='
regex = r'^\h*(\w+) = .*\n+\h*(if|while) \1:'
# example
from os import environ
# before :=
env = environ.get('PATH', None)
if env:
print(env)
@JRiggles
JRiggles / MREH2A.txt
Last active February 13, 2023 19:30
Default answer for poor Stackoverflow questions
Please refer to this guide on how to provide a [mre], and read about [ask]. Remember, we can't help you if we don't know what you've already tried.
@JRiggles
JRiggles / ndx.rb
Created January 21, 2020 20:20
Roll N dice with X sides (NdX) and get the results
def roll (n,d)
arr = []
n.times do
arr.push(rand(1..d))
end
puts "Min: #{n}"
puts "Max: #{n * d}"
puts "Expected: #{(n + n * d) / 2}" # The Expexted roll value is rounded down
puts "Total: #{arr.sum}"
puts "Rolls: #{arr}"
@JRiggles
JRiggles / Array_Pair_Generator.rb
Last active September 14, 2021 17:51
Takes an input array and pairs each element with another from the array. Elements cannot be paired with themselves.
a = %w[A B C D E F G H]
a.shuffle!.zip(a.rotate).sort.each { |k,v| puts "#{k}=>#{v}" }
# example return value:
# A=>E
# B=>D
# C=>A
# D=>H
# E=>B
# F=>C
@JRiggles
JRiggles / ko.js
Last active September 14, 2021 17:53
Calls the given callback() function when the Konami Code is entered. The 'keyPhrase' array can be modified to whatever you like!
function konami(callback) {
const keyPhrase = [
"ArrowUp", "ArrowUp", "ArrowDown", "ArrowDown", "ArrowLeft", "ArrowRight", "ArrowLeft", "ArrowRight", "b", "a", "Enter"
];
let index = 0;
$(document).on("keydown", (k) => { // get the key that was pressed
k.key === keyPhrase[index] ? index++ : (index = 0); // goto next index for each correct key press
if (index === keyPhrase.length) { // if the entire keyPhrase is entered correctly...
index = 0; // clear the index so we can use this function again
callback(); // call the passed-in function