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 / pre-commit.sh
Last active November 13, 2019 17:38
A simple pre-commit hook to halt commits if Rubocop fails. Can be overridden if necessary.
#!/usr/bin/env ruby
require 'english'
require 'rubocop'
ADDED_OR_MODIFIED = /A|AM|^M/.freeze
changed_files = `git status --porcelain`.split(/\n/).
select { |file_name_with_status|
file_name_with_status =~ ADDED_OR_MODIFIED
@ty-porter
ty-porter / api_failure_app.rb
Created February 20, 2020 21:31 — forked from bitwerx-tyler/api_failure_app.rb
Custom failure app for devise-jwt to respond in JSON format
# frozen_string_literal: true
module Devise
# Failure application that will be called every time :warden is thrown from
# any strategy or hook. This application overrides the default Devise
# failure application in order to render messages as JSON.
class ApiFailureApp < Devise::FailureApp
def respond
json_api_error_response
end
@ty-porter
ty-porter / bot.py
Last active March 14, 2020 18:31
Reddit bot for updating flair to top commenter's username after 48 hours
import sys
import traceback
import datetime
import praw
BOT_USERNAME = 'BOT_USERNAME'
BOT_PASSWORD = 'BOT_PASSWORD'
BOT_CLIENT_ID = 'BOT_CLIENT_ID'
BOT_CLIENT_SECRET = 'BOT_CLIENT_SECRET'
@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'
@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
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 / 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 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 / 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 / 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)