Skip to content

Instantly share code, notes, and snippets.

View ty-porter's full-sized avatar
🚴

Tyler Porter ty-porter

🚴
View GitHub Profile
@ty-porter
ty-porter / .zsh-aliases
Last active December 12, 2021 15:57
zsh Prompt Configuration
# Rails
alias be="bundle exec"
alias ber="bundle exec rails"
# git
alias gcm="git commit -m"
alias gp="git push"
alias gst="git status"
alias gco="git checkout"
@ty-porter
ty-porter / assembler.py
Created August 27, 2021 03:16
A toy assembler written in Python
class Assembler:
def __init__(self, program):
self.program = program
self.registers = {}
self.program_counter = 0
def run(self):
while self.program_counter < len(self.program):
fn_name, *args = self.program[self.program_counter].split(" ")
fn = getattr(self, fn_name)
@ty-porter
ty-porter / export_factory.rb
Created July 24, 2021 13:25
Fixture factory
# frozen_string_literal: true
FactoryBot.define do
factory :export do
skip_create
initialize_with do
new(attributes, type)
end
transient do
@ty-porter
ty-porter / memory_killer.rb
Created May 18, 2021 17:27
Sidekiq/Heroku MemoryKiller middleware
# frozen_string_literal: true
require 'platform-api'
# Adapted from GitLab
#
# Docs: https://docs.gitlab.com/ee/administration/operations/sidekiq_memory_killer.html
# Source: https://gitlab.com/gitlab-org/gitlab-foss/-/blob/master/lib/gitlab/sidekiq_daemon/memory_killer.rb
class Sidekiq::Middleware::MemoryKiller
# Default the RSS limit to 0, meaning the MemoryKiller is disabled (kilobytes)
@ty-porter
ty-porter / minimal_square.py
Created October 1, 2020 18:22
Codewars Solutions
# Your task is to find the minimum SQUARE area in which you can place two identical rectangles. The sides of the rectangles should be parallel to the sides of the square.
# You are given two identical rectangles with side lengths a and b with 1 <= a, b <= 100.
# Find the square with minimum area that contains both given rectangles. Rectangles can be rotated (both or just one) and moved, but the sides of the rectangles should be parallel to the sides of the desired square.
def minimal_square(a, b):
# This solution abuses the fact that we can multiply by True/False:
# For instance, 1 * True = 1 and 1 * False = 0
#
# A step further:
@ty-porter
ty-porter / bot.py
Last active June 10, 2020 03:16
Voting bot that removes posts if threshold is not met
import praw
from datetime import datetime
class Bot:
REDDIT = praw.Reddit(username='REDDIT_USERNAME',
password='REDDIT_PASSWORD',
client_id='REDDIT_CLIENT_ID',
client_secret='REDDIT_CLIENT_SECRET',
@ty-porter
ty-porter / bot.py
Created June 2, 2020 14:39
Blacklist Notification Bot
import praw
SUBREDDIT = 'test'
REPLY_USERNAME = 'AlternisBot'
KEYWORDS = ['these', 'words', 'trigger', 'a', 'reply']
BLACKLISTED_KEYWORDS = ['only', 'if', 'these', 'are', 'absent']
reddit = praw.Reddit(username='REDDIT_USERNAME',
password='REDDIT_PASSWORD',
client_id='REDDIT_CLIENT_ID',
@ty-porter
ty-porter / bot.py
Last active April 24, 2020 15:46
Bot to only allow posts to exist for 15 minutes
import datetime
import praw
import traceback
import sys
BOT_USERNAME = 'BOT_USERNAME'
BOT_PASSWORD = 'BOT_PASSWORD'
BOT_CLIENT_ID = 'BOT_CLIENT_ID'
BOT_CLIENT_SECRET = 'BOT_CLIENT_SECRET'
@ty-porter
ty-porter / README.md
Created April 15, 2020 07:04
A Reddit script to continuously count similar posts you've made in the past

Usage

python post_count_bot.py

Exports data to post_counts.csv, and overwrites the file every time you make a post on Reddit.

@ty-porter
ty-porter / bot.py
Created March 14, 2020 18:32
Reddit bot for generating a CSV file for stale moderators
from bs4 import BeautifulSoup
import csv
import datetime
import praw
import requests
import traceback
import sys
BOT_USERNAME = 'BOT_USERNAME'